加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式实例(c语言)

发布时间:2020-12-14 02:21:25 所属栏目:百科 来源:网络整理
导读:#include stdio.h#include sys/types.h#include regex.hint main(int argc,char**argv){int status;int i;int cflags = REG_EXTENDED;regmatch_t pmatch[1];const size_t nmatch =1 ;regex_t reg;const char * pattern="^[A-Z]{2}w+@w{6}_w+.w+$"; /
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>

int main(int argc,char**argv)
{
	int status;
	int i;
	int cflags = REG_EXTENDED;
	regmatch_t pmatch[1];
	const size_t nmatch =1 ;
	regex_t reg;
	const char * pattern="^[A-Z]{2}w+@w{6}_w+.w+$";
        //const char * pattern="^[A-Z]{2}w+$";
        //const char * pattern="^w$";
	
	regcomp(?,pattern,cflags);
	status=regexec(?,argv[1],nmatch,pmatch,0);
        printf("%s",argv[1]);
	if(status == REG_NOMATCH)
		printf("no Matchn");
	else if(status ==0)
	{
		printf("matchn");
	}
}
匹配AA1111@222221_0.0格式的字符串

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读