设为首页 加入收藏

TOP

C语言正则表达式的使用(二)
2014-04-06 17:41:53 来源: 作者: 【 】 浏览:314
Tags:语言 正则 表达式 使用

 

  以下是例子:(环境 centos)

  /*  write by gx

  *  time:2014/3/21

  *  for: test regex

  *  */

  #include <REGEX.H>

  #include <SYS types.h>

  #include <STDIO.H>

  int main(int argc,char** argv)

  {

  int status;

  int i;

  int cflags = REG_EXTENDED;

  regmatch_t pmatch ;

  const size_t nmatch = 1;

  regex_t reg;

  const char* pattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$";

  char* buf = "helloworld12345@qq.com";

  regcomp( , pattern, cflags );

  status = regexec( , buf, nmatch, pmatch, 0 );

  if( REG_NOMATCH == status )

  {

  printf("-----no nomatch--------");

  return 0;

  }

  if( status == 0 )

  {

  printf("match:\n");

  for( i=pmatch[0].rm_so; i<PMATCH[0].RM_EO; pre }< 0; return regfree(?); } printf(?\n ); putchar(buf[i]); { ) i++><BR>

  <P><BR>

  </P>

      

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇字符串替换空格实例题 下一篇C语言单元测试

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: