MS在VS2010的版本里已经添加了C++对正则表达式处理的支持,相应的方法都在一个文件里,如下:

  1. #include <iostream> 
  2. #include <string> 
  3. #include <regex> 

下面看看具体的描述:

c-string/c-string (1
template <class traits, class charT>
  basic_string<charT> regex_replace (const charT* s,
)          const basic_regex<charT,traits>& rgx,
          const charT* fmt,
          regex_constants::match_flag_type flags = regex_constants::match_default);
字裤/字符串(2)
template <class traits, class charT, class ST, class SA>
  basic_string<charT> regex_replace (const charT*s,
          const basic_regex<charT,traits>& rgx,
          const basic_string<charT,ST,SA>& fmt,
          regex_constants::match_flag_type flags = regex_constants::match_default);
字符串/字裤(3)
template <class traits, class charT, class ST, class SA>
  basic_string<charT,ST,SA> regex_replace (const basic_string<charT,ST,SA>& s,
          const basic_regex<charT,traits>& rgx,
          const charT* fmt,
          regex_constants::match_flag_type flags = regex_constants::match_default);
字符串/字符串(4)
template <class traits, class charT, class ST, class SA, class FST, class FSA>
  basic_string<charT,ST,SA> regex_replace (const basic_string<charT,ST,SA>& s,
          const basic_regex<charT,traits>& rgx,
          const basic_string<charT,FST,FSA>& fmt,
          regex_constants::match_flag_type flags = regex_constants::match_default);
范围/字裤(5)
template <class OutputIterator, class BidirectionalIterator,
          class traits, class charT>
  OutputIterator regex_replace (OutputIterator out,
          BidirectionalIterator first, BidirectionalIterator last,
          const basic_regex<charT,traits>& rgx,
          const charT* fmt,
          regex_constants::match_flag_type flags = regex_constants::match_default);
范围/字符串(6)
template <class OutputIterator, class BidirectionalIterator,
          class traits, class charT, class ST, class SA>
  OutputIterator regex_replace (OutputIterator out,
          BidirectionalIterator first, BidirectionalIterator last,
          const basic_regex<charT,traits>& rgx,
          const basic_string<charT,ST,SA>& fmt,
          regex_constants::match_flag_type flags = regex_constants::match_default);
替换匹配的序列
就是一个复制的目标序列(主体)与所有与正则表达式匹配的rgx(模式)取代了fmt(替换)。目标序列要么是年代或字符序列之间的第一个和最后一个,这取决于使用的版本。

由此产生的顺序返回字符串对象在版本1、2、3和4。版本5和6带一个输出迭代器作为第一个参数,用于存储生成的序列。

一个可选参数,旗帜,允许指定选项如何匹配和格式表达。

参数

s
一个字符串与目标序列(主题)。
RGX
一个基本正则表达式对象(模式)来匹配。
fmt
一个字符串替换每个匹配。
这可能包括格式说明符和转义序列,取而代之的是,它们表示的字符。对于格式默认,可能说明符是:
字符 替换
$N backreference开方(即。,一份第n个括号匹配组指定的正则表达式模式)。
n必须一个整数值指定一个有效的backreference,大于1,两位数最多的。
$& 复制整个比赛
$$ 前缀(即。,部分目标序列前面匹配)。
´美元 后缀(即。,部分的目标序列,遵循匹配)。
$$ 一个$字符。
旗帜
标志用于控制rgx如何匹配和fmt是如何格式化。
一个或更多的这些常量可以组合(使用按位或运算符,|)形成一个有效的位掩码值的类型regex常量::匹配标志类型:
旗* 效果 笔记
match_default 默认 默认匹配行为。
这个常数的值为零* *。
match_not_bol 不是开始的行 第一个字符是不被认为是一个开始的线(“^”不匹配)。
match_not_eol 没有行尾 最后一个字符是不被视为一个行将就木的(“$”不匹配)。
match_not_bow 不是开始的字 的转义序列“\ b”不符合作为一个单词的开始。
match_not_eow 没有结束的单词 的转义序列“\ b”不匹配作为结束的单词。
match_any 任何比赛 任何比赛是可以接受的,如果超过一个比赛是可能的。
match_not_null 非空 空序列不匹配。
match_continuous 连续 表达式必须匹配一个时间将从第一个字符。
将必须开始在第一个字符匹配。
匹配prev效果 之前的可用 一个或多个字符出现之前,第一个。(比赛不是波尔和匹配不弓被忽略)
format_default 默认格式 使用标准格式规则替换匹配(所使用的ECMAScript的替代方法)。
这个常数的值为零* *。
format_sed sed格式化 使用相同的规则作为sed效用在POSIX替换匹配。
format_no_copy 没有复制 在目标序列的部分不匹配正则表达式不匹配时复制替换。
format_first_only 第一只 只有第一次出现的正则表达式替换。
*这些位掩码标志名称可根据std::regex常量名称空间(见regex常量为更多的细节)。
* *常量值为零是忽略了如果其他一些标志被设置。
是一个类型的匹配标记类型下的可用std::regex常量名称空间。
输出迭代器指向第一个字符的一个序列,其中产生的顺序存储。
函数模板类型可以是任何类型的输出迭代器到字符。
第一,最后
双向迭代器到初始的和最终的职位范围的字符作为目标序列的匹配。使用范围是[第一个、最后一个),包括所有的角色在第一和最后,包括字符指出第一而不是字符指出去年。
函数模板类型可以是任何类型的双向迭代器到字符。

返回值

版本1、2、3和4返回字符串对象与结果序列。
版本5和版本6的回归。