如何从VC ++ 2010中的std :: regex获取字符串模式 [英] How to get string with pattern from std::regex in VC++ 2010
问题描述
我可以从 std :: regex
获取正则表达式的字符串吗?
Can I get the string with regular expression from std::regex
? Or should I save it somewhere else if I want to use it later?
在boost中,您可以执行以下操作:
In boost you can do this:
boost::regex reg("pattern");
string p = reg.str();
或使用<
cout<
cout << reg;
will print aaa.
但在 std :: regex $> c $ c>没有str()或运算符<<
but in std::regex
there is no str() or operator<<. Should I save my string somewhere else or I just can't find it?
在调试器中我可以看到 std :: regex
In debugger I can see what's in std::regex
.
推荐答案
我刚看过N3225的第28.4节(标题< regex> ;
概要),而且 basic_regex
模板没有成员函数 str
I just looked in N3225, section 28.4 (header <regex>
synopsis) and indeed, the basic_regex
template has no member function str
, and there are no operator<<
provided.
段落28.8 / 2提供
The paragraph 28.8/2 provides a little insight on this :
类型特殊化的对象basic_regex
负责
将charT
对象的序列转换为内部表示。
没有指定这个
表示所采用的形式,也不能通过对
正则表达式进行操作的算法访问
。
Objects of type specialization of
basic_regex
are responsible for converting the sequence ofcharT
objects to an internal representation. It is not specified what form this representation takes, nor how it is accessed by algorithms that operate on regular expressions.
我理解的是, basic_regex
的标准命令可以从 const charT * code>,但不要求实现保留此字符串。
What I understand is that the standard mandates that basic_regex
can be constructed from const charT *
but does not require the implementation to keep this string.
这篇关于如何从VC ++ 2010中的std :: regex获取字符串模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!