PCRE簡單應用

2021-07-08 17:07:21 字數 1860 閱讀 6376

有那麼一點點明白pcre強大的地方了,正規表示式確實很牛掰呀,對文字行進行斷句,斷句的符號即為標點符號,**如下:

#include 

#include

#include

#include "pcre.h"

#include

#include

#include

#include

#include "ul_ccode.h"

#include "ul_conf.h"

#include "ul_log.h"

#define n 10240

#define m 30

int main(int argc, char *argv)

file *fp_in;

file *fp_out;

fp_in = fopen(argv[1], "rb");

fp_out = fopen(argv[2], "wb");

if(null == fp_in || null == fp_out)

const

char *error;

pcre *re;

int erroffset;

int ovector[m];

int rc = 0, i = 0;

char buffer[n];

memset(buffer, 0, n);

// pattern

//char pattern[n] = "(0|1|2|3|4|5|6|7|8|9)";

char pattern[n] = "(,|。| |\t|「|」|;)";

printf("%s\n", pattern);

ul_trans2bj(pattern, buffer);

ul_trans2lower(buffer, pattern);

printf("%s\n", pattern);

re = pcre_compile(pattern, 0, &error, &erroffset, null);

if(null == re)

char line[n], line1[n], line2[n], line_out[n];

char *p1 = null, *p2 = null;

int len = 0;

int num = 0;

std::string str;

std::vector

svec;

std::vector

::iterator iter;

while(fgets(line, n, fp_in))

len = strlen(p2);

if(ovector[0] > 0)

if(ovector[1] < len)

else

}if(svec.size() > 0)

//strncpy(line1, line, n);

//if(0 == len)

// continue;

//line[len] = '\0';

//strncpy(line1, line, n);

fprintf(fp_out, "%s\n", line2);

}fclose(fp_in);

fclose(fp_out);

pcre_free(re);

return

0;}

其中的兩個函式的意思,

ul_trans2bj(pattern, buffer);

//將字串轉為半形字串

ul_trans2lower(buffer, pattern);

//轉為小寫字串

pcre安裝報錯

yum y install libtool gcc c 在執行安裝上,一定要確認上面的兩個包已經安裝。第一處出錯 configure error newly created file is older than distributed files 上面的報錯是因為機器的時間設定不對,可能過下面方法設...

PCRE配置共享庫

問題資訊 nginx error while loading shared libraries libpcre.so.1 cannot open shared object file no such file or directory 問題原因 沒有安裝pcre庫,或安裝了pcre庫而沒有配置pcr...

編譯安裝Nginx和pcre

編譯安裝ngnix和pcre 一 首先要安裝pcre 他作用是讓ngnix支援rewrite功能 yum y install make zlib zlib devel gcc c libtool mkdir p home oldboy tools cd home oldboy tools wget ...