eybuild-x86-arm920t-2.6.7.tar
很好的嵌入式WEB开发环境
源代码在线查看: main.csp
Regular Expressions
body {font-size: 12px;}
#checkbox {font-size: 10px;}
#radiobox {font-size: 10px;}
#listbox {font-size: 10px;}
#ok {bold; color=black;}
#error {bold; color=red;}
-->
preg_match(), preg_match_all(), preg_split(), preg_replace()
字符串匹配
匹配所有
字符串分离
字符串替换
正则表达式:
不区分大小写
多行模式
输入比较串:
输入替换串:
#define MLIST_SIZE 4096
char errbuf[256] = "正确匹配!";
regmatch_t mlist[MLIST_SIZE];
char * plist[MLIST_SIZE];
char pattern[256] = "";
regmatch_t * pmlist = mlist;
char * string = G("string");
const char * repstr[MLIST_SIZE];
char * prep = NULL;
char * pdst = NULL;
int ret;
int len, i;
int mode = atoi(G("mode"));
/* make pattern */
sprintf(pattern, "/%s/%s%s", G("pattern"),
'1'==G("nocase")[0] ? "i": "", '1'==G("mline")[0] ? "m": "");
/* perform match */
if (3 == mode) {
char * ps;
char * pe;
ps = prep = strdup(G("repstr"));
for (i=0; NULL != ps && i if (NULL != (pe=strchr(ps, '\n')))
*pe++ = '\0';
repstr[i] = strtrim(ps);
}
repstr[i] = NULL;
ret = preg_replace(pattern, string, repstr, &pdst, 512*128, MLIST_SIZE);
}
else if (2 == mode)
ret = preg_split(pattern, string, plist, MLIST_SIZE);
else if (1 == mode)
ret = preg_match_all(pattern, string, &pmlist, MLIST_SIZE);
else
ret = preg_match(pattern, string, pmlist, MLIST_SIZE);
if (ret regerror(REG_GETERR(ret), NULL, errbuf, sizeof(errbuf));
%>
匹配结果:
:
模式串:
匹配串:
0) { %>
替换串:
共替换:
free(pdst);
free(prep);
%>
. (-:-)
preg_split_free(plist);
%>
len = pmlist[i].rm_eo - pmlist[i].rm_so;
%>
. (: )
char * p = strndup(string+pmlist[i].rm_so, len);
ebHtmlPrint(p);
free(p);
}
ebHtmlnPrint(string+pmlist[i].rm_so, len);
/* =%.*s, len, string+pmlist[i].rm_so */ %>
if (1 == mode)
free(pmlist);
%>