您当前的位置: 首页 >  c++

phymat.nico

暂无认证

  • 0浏览

    0关注

    1967博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++正则表达式的使用

phymat.nico 发布时间:2017-12-11 09:35:55 ,浏览量:0

C++里面使用正则表达式一般有三种:C regex,C ++regex,boost regex

C regex 的速度是最快的 C++ regex 速度一般 boost regex 速度最慢,但是用起来最方便

速度上大约是这么个情况:V(C)=5V(C++)=10(Boost) [声明:以上速度是个人测试,仅供参考]

下面看用法:

C++版本:

// Regex.cpp : 定义控制台应用程序的入口点。
//
#include 
#include 
#include 
#include 
using namespace std;

//电子邮件匹配
bool is_email_valid(const std::string& email)
{
   const regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
   /****
    const std::regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+"); 
   std:: match_results result;
   bool valid = std::regex_match(email, result,pattern);
   //此处result参数可有可无,result是一个字符串数组,用来存储正则表达式里面括号的内容。
   if(valid&&(result.length()>0))
  {
      for(int i =0;i            
关注
打赏
1659628745
查看更多评论
0.0439s