麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C > 正文

pcre函數詳細解析

2020-02-24 14:26:43
字體:
來源:轉載
供稿:網友

PCRE是nfa正則化引擎,但是它實現了dfa,雖然只是滿足數學意義上的規則,那么pcre函數詳細解析大家都了解嗎?別著急,武林技術頻道小編為大家細細道來。

1. pcre_compile

原型:
#include <pcre.h>
pcre *pcre_compile(const char *pattern, int options, const char **errptr, int *erroffset, const unsigned char *tableptr);

功能:將一個正則表達式編譯成一個內部表示,在匹配多個字符串時,可以加速匹配。其同pcre_compile2功能一樣只是缺少一個參數errorcodeptr。

參數:
pattern??? 正則表達式
options???? 為0,或者其他參數選項
errptr出錯消息
erroffset? 出錯位置
tableptr?? 指向一個字符數組的指針,可以設置為空NULL

示例:

?

L1720???? re = pcre_compile((char *)p, options, &error, &erroroffset, tables);


2. pcre_compile2

?

原型:
#include <pcre.h>
pcre *pcre_compile2(const char *pattern, int options, int *errorcodeptr, const char **errptr, int *erroffset, const unsigned char *tableptr);

功能:將一個正則表達式編譯成一個內部表示,在匹配多個字符串時,可以加速匹配。其同pcre_compile功能一樣只是多一個參數errorcodeptr。

參數:
pattern??? 正則表達式
options???? 為0,或者其他參數選項
errorcodeptr??? 存放出錯碼
errptr出錯消息
erroffset? 出錯位置
tableptr?? 指向一個字符數組的指針,可以設置為空NULL

3. pcre_config

原型:
#include <pcre.h>
int pcre_config(int what, void *where);

功能:查詢當前PCRE版本中使用的選項信息。

參數:
what? 選項名
where存儲結果的位置

示例:

Line1312 (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);

4. pcre_copy_named_substring

原型:
#include <pcre.h>
int pcre_copy_named_substring(const pcre *code, const char *subject, int *ovector, int stringcount, const char *stringname, char *buffer, int buffersize);

功能:根據名字獲取捕獲的字串。

參數:
code成功匹配的模式
subject 匹配的串
ovectorpcre_exec() 使用的偏移向量
stringcount?? pcre_exec()的返回值
stringname捕獲字串的名字
buffer?? 用來存儲的緩沖區
buffersize???? 緩沖區大小

示例:

?

Line2730 int rc = pcre_copy_named_substring(re, (char *)bptr, use_offsets,

?

count, (char *)copynamesptr, copybuffer, sizeof(copybuffer));


5. pcre_copy_substring

?

原型:
#include <pcre.h>
int pcre_copy_substring(const char *subject, int *ovector, int stringcount, int stringnumber, char *buffer, int buffersize);

功能:根據編號獲取捕獲的字串。

參數:
code成功匹配的模式
subject 匹配的串
ovectorpcre_exec() 使用的偏移向量
stringcount?? pcre_exec()的返回值
stringnumber?? 捕獲字串編號
buffer?? 用來存儲的緩沖區
buffersize???? 緩沖區大小

示例:

?

Line2730 int rc = pcre_copy_substring((char *)bptr, use_offsets, count,

?

i, copybuffer, sizeof(copybuffer));


6. pcre_dfa_exec

?

原型:
#include <pcre.h>
int pcre_dfa_exec(const pcre *code, const pcre_extra *extra, const char *subject, int length, int startoffset, int options, int *ovector, int ovecsize, int *workspace, int wscount);

功能:使用編譯好的模式進行匹配,采用的是一種非傳統的方法DFA,只是對匹配串掃描一次(與Perl不兼容)。

參數:
code???? 編譯好的模式
extra? 指向一個pcre_extra結構體,可以為NULL
subject??? 需要匹配的字符串
length匹配的字符串長度(Byte)
startoffset 匹配的開始位置
options???? 選項位
ovector??? 指向一個結果的整型數組
ovecsize?? 數組大小
workspace 一個工作區數組
wscount?? 數組大小

示例:

?

Line2730 count = pcre_dfa_exec(re, extra, (char *)bptr, len, start_offset,

?

options | g_notempty, use_offsets, use_size_offsets, workspace,

sizeof(workspace)/sizeof(int));


7. pcre_copy_substring

?

原型:
#include <pcre.h>
int pcre_exec(const pcre *code, const pcre_extra *extra, const char *subject, int length, int startoffset, int options, int *ovector, int ovecsize);

功能:使用編譯好的模式進行匹配,采用與Perl相似的算法,返回匹配串的偏移位置。。

參數:
code???? 編譯好的模式
extra? 指向一個pcre_extra結構體,可以為NULL
subject??? 需要匹配的字符串
length匹配的字符串長度(Byte)
startoffset 匹配的開始位置
options???? 選項位
ovector??? 指向一個結果的整型數組
ovecsize?? 數組大小

8. pcre_free_substring

原型:
#include <pcre.h>
void pcre_free_substring(const char *stringptr);

功能:釋放pcre_get_substring()和pcre_get_named_substring()申請的內存空間。

參數:
stringptr???? 指向字符串的指針

示例:

?

Line2730 const char *substring;

?

int rc = pcre_get_substring((char *)bptr, use_offsets, count,

i, &substring);

……

pcre_free_substring(substring);


9. pcre_free_substring_list

?

原型:
#include <pcre.h>
void pcre_free_substring_list(const char **stringptr);

功能:釋放由pcre_get_substring_list申請的內存空間。

參數:
stringptr???? 指向字符串數組的指針

示例:

?

Line2773 const char **stringlist;
int rc = pcre_get_substring_list((char *)bptr, use_offsets, count,
……
pcre_free_substring_list(stringlist);


10. pcre_fullinfo

?

原型:
#include <pcre.h>
int pcre_fullinfo(const pcre *code, const pcre_extra *extra, int what, void *where);

功能:返回編譯出來的模式的信息。

參數:
code?? 編譯好的模式
extra? pcre_study()的返回值,或者NULL
what? 什么信息
where存儲位置

示例:

?

Line997?? if ((rc = pcre_fullinfo(re, study, option, ptr)) < 0)
fprintf(outfile, "Error %d from pcre_fullinfo(%d)/n", rc, option);
}


11. pcre_get_named_substring

?

原型:
#include <pcre.h>
int pcre_get_named_substring(const pcre *code, const char *subject, int *ovector, int stringcount, const char *stringname, const char **stringptr);

功能:根據編號獲取捕獲的字串。

參數:
code成功匹配的模式
subject 匹配的串
ovectorpcre_exec() 使用的偏移向量
stringcount?? pcre_exec()的返回值
stringname捕獲字串的名字
stringptr???? 存放結果的字符串指針

示例:

?

Line2759 const char *substring;
int rc = pcre_get_named_substring(re, (char *)bptr, use_offsets,
count, (char *)getnamesptr, &substring);


12. pcre_get_stringnumber

?

原型:
#include <pcre.h>
int pcre_get_stringnumber(const pcre *code, const char *name);

功能:根據命名捕獲的名字獲取對應的編號。

參數:
code成功匹配的模式
name?? 捕獲名字

13. pcre_get_substring

原型:
#include <pcre.h>
int pcre_get_substring(const char *subject, int *ovector, int stringcount, int stringnumber, const char **stringptr);

功能:獲取匹配的子串。

參數:
subject成功匹配的串
ovectorpcre_exec() 使用的偏移向量
stringcount??? pcre_exec()的返回值
stringnumber? 獲取的字符串編號
stringptr????? 字符串指針

14. pcre_get_substring_list

原型:
#include <pcre.h>
int pcre_get_substring_list(const char *subject, int *ovector, int stringcount, const char ***listptr);

功能:獲取匹配的所有子串。

參數:
subject成功匹配的串
ovectorpcre_exec() 使用的偏移向量
stringcount??? pcre_exec()的返回值
listptr????? 字符串列表的指針

15. pcre_info

原型:
#include <pcre.h>
int pcre_info(const pcre *code, int *optptr, int *firstcharptr);

已過時,使用pcre_fullinfo替代。

16. pcre_maketables

原型:
#include <pcre.h>
const unsigned char *pcre_maketables(void);

功能:生成一個字符表,表中每一個元素的值不大于256,可以用它傳給pcre_compile()替換掉內建的字符表。

參數:

示例:
Line2759 tables = pcre_maketables();

17. pcre_refcount

原型:
#include <pcre.h>
int pcre_refcount(pcre *code, int adjust);

功能:編譯模式的引用計數。

參數:
code已編譯的模式

adjust????? 調整的引用計數值

18. pcre_study

原型:
#include <pcre.h>
pcre_extra *pcre_study(const pcre *code, int options, const char **errptr);

功能:對編譯的模式進行學習,提取可以加速匹配過程的信息。

參數:
code????? 已編譯的模式
options??? 選項
errptr???? 出錯消息

示例:
Line1797 extra = pcre_study(re, study_options, &error);

19. pcre_version

原型:
#include <pcre.h>
char *pcre_version(void);

功能:返回PCRE的版本信息。
參數:
示例:
Line1384 if (!quiet) fprintf(outfile, "PCRE version %s/n/n", pcre_version());

以上就是關于pcre函數詳細解析,如果你還想了解更多專業的信息,建議你可以時常來關注武林技術頻道為大家推出的知識。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 日韩黄在线观看 | 深夜视频福利 | 色播视频网站 | fc2国产成人免费视频 | 欧美成人精品欧美一级乱黄 | 久久网站免费 | 天天草夜夜| 欧美成人午夜一区二区三区 | 中文字幕在线网站 | 国产精品一区在线免费观看 | 高清av在线 | 国产美女视频黄a视频免费 日韩黄色在线播放 | 色婷婷一区二区三区 | 成年毛片 | 欧美日韩国产一区二区三区在线观看 | 成人男女激情免费视频 | 国产噜噜噜噜久久久久久久久 | 国产自在线 | 羞羞的视频免费在线观看 | 在线 日本 制服 中文 欧美 | 精品国产精品久久 | 成人视屏在线 | 狠狠干天天操 | 激情小说色 | 成人精品一区二区 | 一级做人爱c黑人影片 | 国产精品毛片无码 | 精品国产一区二区三区四区阿崩 | 欧美精品一区二区久久 | av91肉丝一区二区电影 | 欧美一级黄视频 | 一区二区久久精品66国产精品 | 黄色a级片视频 | 亚洲视频在线观看免费视频 | 国产亚洲精品一区二区三区 | 国产精品视频 | 国产无限资源在线观看 | 久久久精品视频免费看 | wwwxxx国产| 精精国产xxxx视频在线野外 | 92精品国产自产在线 |