Sword pcre库函数学习一
0.pcre_exec
原型:
#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);
功能:匹配成功返回非负数,没有匹配返回负数
参数:
code 输入参数,用pcre_compile编译好的正则表达结构的指针
extra 输入参数,用来向pcre_exec传一些额外的数据信息的结构的指针
subject 输入参数,要被用来匹配的字符串
length 输入参数, 要被用来匹配的字符串的指针
startoffset 输入参数,用来指定subject从什么位置开始被匹配的偏移量
options 输入参数, 用来指定匹配过程中的一些选项
ovector 输出参数,用来返回匹配位置偏移量的数组,本质上是多维数组
ovecsize 输入参数, 用来返回匹配位置偏移量的数组的最大大小 ovector的最后1/3个空间,即[2n~3n-1],貌似为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 正则表达式
option 为0,或者其他参数选项
errptr 出错信息
erroffset 出错信息
tableptr 指向一个字符数组的指针,可以设置为空NULL
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 存储结果的位置
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 匹配的串
ovector pcre_exec()使用的偏移向量
stringcount pcre_exec()的返回值
stringname 捕获字串的名字
buffer 用来存储的缓冲区
buffersize 缓冲区大小
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 匹配的串
ovector pcre_exec()使用的偏移向量
stringcount pcre_exec()的返回值
stringnumber 捕获字串编号
buffer 用来存储的缓冲区
buffersize 缓冲区大小
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 数组大小
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 指向字符串的指针
Sword pcre库函数学习一的更多相关文章
- Sword pcre库函数学习三
14.pcre_get_substring_list 原型: #include <pcre.h> int pcre_get_substring_list(const char *subje ...
- Sword pcre库函数学习二
9.pcre_free_substring_list 原型: #include <pcre.h> void pcre_free_substring_list(const char **st ...
- Sword pcre库使用
#include <stdlib.h> #include <string.h> #include "regularhelper.h" #include &q ...
- Sword cjson库函数使用
/* cjson库的使用 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #includ ...
- 在C语言中利用PCRE实现正则表达式
1. PCRE简介 2. 正则表达式定义 3. PCRE正则表达式的定义 4. PCRE的函数简介 5. 使用PCRE在C语言中实现正则表达式的解析 6. PCRE函数在C语言中的使用小例子 1. P ...
- PHP学习笔记 - 进阶篇(5)
PHP学习笔记 - 进阶篇(5) 正则表达式 什么叫正则表达式 正则表达式是对字符串进行操作的一种逻辑公式,就是用一些特定的字符组合成一个规则字符串,称之为正则匹配模式. $p = '/apple/' ...
- PHP学习之-正则表达式
PHP学习之-正则表达式 1.什么是正则表达式 正则表达式是对字符串处理额一种逻辑公式,就是用特定的字符串组合成一个规则的字符串,称之为正则匹配模式 $p = '/apple/'; $str = '' ...
- PCRE-正则库及用法
摘自http://blog.chinaunix.net/uid-26575352-id-3517146.html 在C语言中利用PCRE实现正则表达式 http://www.pcre.org/ ...
- iBase4J部署总结
iBase4J部署总结 序言 最近看到个分布式框架,只有一个字:好.所以部署起来看看.开始的时候说实话遇到了点困难.去码云上看了下,貌似想得到指导要加入一个群,而且需要收费的,反正闲来无事,索性自己搞 ...
随机推荐
- Android Manifest.xml文件的结构及作用
原文链接:http://android.eoe.cn/topic/android_sdk 每一个应用程序在工程的根目录下必须要有一个AndroidManifest.xml文件(一定要用这个名称).这个 ...
- wget常见用法
1.很多软件官网会有安装脚本,并把脚本搞成raw模式,方便下载后直接运行的shell文件.比如docker wget -qO- get.docker.com | bash -q的含义是:--quiet ...
- Go基础--终端操作和文件操作
终端操作 操作终端相关的文件句柄常量os.Stdin:标准输入os.Stdout:标准输出os.Stderr:标准错误输出 关于终端操作的代码例子: package main import " ...
- sqlserver自定义函数与存储过程的区别 实例详解
分享下sql server自定义函数与存储过程的区别,一起来学习下. 一.自定义函数: 1. 可以返回表变量 2. 限制颇多,包括 不能使用output参数: 不能用临时表: 函数内部的操作不能影响到 ...
- Modelsim se仿真Xilinx IPcore
Modelsim se仿真Xilinx IPcore 方法:先写好do文件常规框架,根据modelsim报错再添加ise IP核库仿真文件.注:记得添加并仿真glbl.v全局控制仿真文件到sim/is ...
- 《Android源代码设计模式解析》读书笔记——Android中你应该知道的设计模式
断断续续的,<Android源代码设计模式解析>也看了一遍.书中提到了非常多的设计模式.可是有部分在开发中见到的几率非常小,所以掌握不了也没有太大影响. 我认为这本书的最大价值有两点,一个 ...
- (转)在Docker中运行Java:为了防止失败,你需要知道这些
转自:https://mp.weixin.qq.com/s?__biz=MzA5OTAyNzQ2OA==&mid=2649693848&idx=1&sn=4e9ef7e2a9d ...
- Effective Spark RDDs with Alluxio【转】
转自:http://kaimingwan.com/post/alluxio/effective-spark-rdds-with-alluxio 1. 介绍 2. 引言 3. Alluxio and S ...
- 【Socket】linux下http服务器开发
1.mystery引入 1)超文本传输协议(HTTP)是一种应用于分布式.合作式.多媒体信息系统的应用层协议 2)工作原理 1)客户端一台客户机与服务器建立连接后,会发送一个请求给服务器,请求方式的格 ...
- Python字符串、时间戳、datetime时间相关转换
总结的时间转换函数 # datetime时间转为字符串 def Changestr(datetime1): str1 = datetime1.strftime('%Y-%m-%d %H:%M:%S') ...