正则表达式 匹配

字符串:

void ABTR("quint32 ab")
{
 string s = TR("sky is blue.");
 obj.foo(TR('rose is red.'));
 obj.foo(TR('rose is red."));
 obj.foo(TR("Mike (Mike Lee)say /"He is hungury/""))

}

 

正则表达式:(?<!/w)(?:TR/()('|")(.*)/1(?:/))

 

C++ boost:

boost中*贪婪匹配所以后面加了?,C#中则不需要

 

boost中设计到的正则表达式的类:

namespace boost{

template <class charT, class traits = regex_traits<charT>  >
class basic_regex;

typedef basic_regex<char>      regex;
typedef basic_regex<wchar_t>   wregex;

}

表示一个正则表达式

 

**************

 

template <class BidirectionalIterator,
         class Allocator = std::allocator<sub_match<BidirectionalIterator> >
class match_results;

typedef match_results<const char*>              cmatch;
typedef match_results<const wchar_t*>           wcmatch;
typedef match_results<string::const_iterator>   smatch;
typedef match_results<wstring::const_iterator>  wsmatch;

 

返回一个匹配结果,其中包含由sub_match组成的分组(正则表达式中圆括号内的子表达式为一个分组)

[0]也是一个sub_match表示整个正则表达式所匹配的子串,其中的first,second代表整个子串的开始位置和结束位置。

[1]。。。则为依次的分组

 

************



template <class BidirectionalIterator>
class sub_match;

typedef sub_match<const char*>                    csub_match;
typedef sub_match<const wchar_t*>                 wcsub_match;
typedef sub_match<std::string::const_iterator>    ssub_match;
typedef sub_match<std::wstring::const_iterator>   wssub_match;

 代表一个分组,sub_match继承自std::pair,其中first表示匹配到的字串的起始位置,second为结束位置

sub_match可隐式转换为一个字符串类型

 

**************

2个函数:

regex_match   //完整匹配,整个待匹配串完全符合正则表达式时,返回true


regex_search  //部分匹配,找其中匹配的子串

 

 


 

C#

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值