易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++中使用正则表达式

头文件regex.h中定义了c/c++使用正则表达式的函数: regcomp(), regexec(), regerror(), and regfree() 。regcomp()编译正则表达式,regexec()匹配正则表达式, regfree()释放正则表达式,regerror()报告正则表达式错误信息。使用方法如下代码所示:
static string merge_path(const string base, const string path)
{
static regex_t re;


static int initialized = 0;
regmatch_t pm[1];
string p, s;
size_t len;
assert(*path != '/');
if (base && (p = strrchr(base, '/'))) {
newarray(s, (p - base) + strlen(path) + 2);
strncpy(s, base, (p - base) + 1);
strcpy(s + ((p - base) + 1), path);
} else {
newarray(s, strlen(path) + 2);
#if 0
s[0] = '/';
strcpy(s + 1, path);
#else
strcpy(s, path);
#endif
}
/* Replace all substrings of form "/xxx/../" with "/" */
if (! initialized) {
assert(regcomp(&re, "/[^/]+/\\.\\./", REG_EXTENDED) == 0);
initialized = 1;
}
len = strlen(s);


while (regexec(&re, s, 1, pm, 0) == 0) {
memmove(s + pm[0].rm_so, s + (pm[0].rm_eo - 1), len - pm[0].rm_eo + 2);
len -= pm[0].rm_eo - pm[0].rm_so - 1;
}
/* Replace all substrings of the form "/./" with "/" */
/*len = strlen(s);*/
for (p = s; (p = strstr(p, "/./")); ) {
memmove(p, p + 2, len - (p - s) - 1);
len -= 2;
}
return s;

关于C/C++中正则表达式的规则,现将opengroup.org的教程摘抄如下:(原文链接http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_06)
<<< Previous
Home
Next >>>
The Open Group Base Specifications Issue 7
IEEE Std 1003.1-2008
Copyright © 2001-2008 The IEEE and The Open Group
9. Regular Expressions
Regular Expressions (REs) provide a mechanism to select specific strings from a set of character strings.
Regular expressions are a context-independent syntax that can represent a wide variety of character sets and character set orderings, where these character sets


相关文档:

VB/C++/C#串口通讯源代码【附详细注释】


VB
    If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
    MSComm1.CommPort = i1
    MSComm1.PortOpen = True
    MSComm1.InputMode = comInputModeBinary
    MSComm1.InBufferCount = 0
& ......

Python嵌入C++详解(3)

继前篇《Import Module》(http://blog.csdn.net/xiadasong007/archive/2009/09/02/4512797.aspx),继续分析嵌入部分基础知识。这次不多说,有什么问题记得多查英文资料,国内的这方面知识少
还是来看代码,写完我就睡觉了~
 
#include "python/python.h"
#include <iostream>
using namespace std;
int ......

SQLite C/C++接口介绍

这篇文章是使用SQLite C/C++接口的一个概要介绍和入门指南。
由于早期的SQLite只支持5个C/C++接口,因而非常容易学习和使用,但是随着SQLite功能的增强,新的C/C++接口不断的增加进来,到现在有超过150个不同的API接口。这往往使初学者望而却步。幸运的是,大多数SQLite中的C/C++接口是专用的,因而很少被使用到。尽管有这 ......

Delphi 与 C/C++ 数据类型对照表

Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号