资源简介
正则表达式是一个很强的工具,可以在你的软件中增强查找、替换、匹配等功能。附件中封装了Henry Spencer的regex library源码,有说明和范例,纯C可移值,简单易用。
代码片段和文件信息
/**
* @file JRegex.c
*
* @brief Regular expression functions
*
* Original code by Henry Spencer
* Henry Spencer‘s regex library
* ftp://ftp.zoo.toronto.edu/pub/bookregexp.{tar|shar}
* or http://www.arglist.com/regex/files/regexp.old.tar.Z
*
* Wrapped by JoStudio
*
*
*/
//=================Start of wapped Henry Spencer‘s regex library ==============
// Functions written by Henry Spencer
/*
* regmagic.h regcomp and regexec are include
*/
#include
#include
#include
#include
///#include
//==== start of “regex.h“ =======
/*
* Definitions etc. for regexp(3) routines.
*
* Caveat: this is V8 regexp(3) [actually a reimplementation thereof]
* not the System V one.
*/
#define NSUBEXP 10
typedef struct regexp {
char *startp[NSUBEXP];
char *endp[NSUBEXP];
char regstart; /* Internal use only. */
char reganch; /* Internal use only. */
char *regmust; /* Internal use only. */
int regmlen; /* Internal use only. */
char program[1]; /* Unwarranted chumminess with compiler. */
} regexp;
regexp *regcomp(const char *re);
int regexec(regexp *rp const char *s);
void regsub(const regexp *rp const char *src char *dst);
void regerror(char *message);
//==== end of “regex.h“ =======
///#include
//==== start of “regmagic.h“ =======
/*
* The first byte of the regexp internal “program“ is actually this magic
* number; the start node begins in the second byte.
*/
#define MAGIC 0234
//==== end of “regmagic.h“ =======
//==== start of “regexp.c“ =======
/*
* The “internal use only“ fields in regexp.h are present to pass info from
* compile to execute that permits the execute phase to run lots faster on
* simple cases. They are:
*
* regstart char that must begin a match; ‘\0‘ if none obvious
* reganch is the match anchored (at beginning-of-line only)?
* regmust string (pointer into program) that match must include or NULL
* regmlen length of regmust string
*
* Regstart and reganch permit very fast decisions on suitable starting points
* for a match cutting down the work a lot. Regmust permits fast rejection
* of lines that cannot possibly match. The regmust tests are costly enough
* that regcomp() supplies a regmust only if the r.e. contains something
* potentially expensive (at present the only such thing detected is * or +
* at the start of the r.e. which can involve a lot of backup). Regmlen is
* supplied because the test in regexec() needs it and regcomp() is computing
* it anyway.
*/
/*
* Structure for regexp “program“. This is essentially a linear encoding
* of a nondeterministic finite-state machine (aka syntax charts or
* “railroad normal form“ in parsing technology). Each node is an opcode
* plus a “next“ pointer possibly plus an operand. “Next“ pointers of
* all nodes except BRANCH implement concatenation; a “next“ pointer with
* a BRANCH on both ends of it is connecting two alternatives. (Here we
* have one of the su 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 40610 2011-06-26 13:59 JRegex.c
文件 4420 2011-06-26 13:59 JRegex.h
文件 3665 2011-06-26 14:30 test.c
文件 6853 2011-06-26 14:37 002 正则表达式(regex)及C语言实现.txt
----------- --------- ---------- ----- ----
55548 4
相关资源
- GD32通过规则组寄存器 DMA获取多组AD
- 基于MFC的TCP调试助手源码95706
- 国际象棋的qt源代码
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- 基于mfc的多线程文件传输
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 利用C++哈希表的方法实现电话号码查
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 移木块游戏,可以自编自玩,vc6.0编写
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- C++纯文字DOS超小RPG游戏
- 个人日常财务管理系统(C语言)
- MFC数字钟(基于VC6.0)
川公网安备 51152502000135号
评论
共有 条评论