开发者

C++ regex: convert C# regex to C++ Linux

开发者 https://www.devze.com 2023-02-05 02:27 出处:网络
I can I convert exactly this regex in c#: Regex (@\"\\s*nameserv开发者_如何学Cer\\s+(?<address>.*)\")

I can I convert exactly this regex in c#:

Regex (@"\s*nameserv开发者_如何学Cer\s+(?<address>.*)")
Regex (@"\s*search\s+(?<domain>.*)")

to std::tr1::regex or to regex.h in C++? (Linux)

thanks!


I don't know the std::tr1::regex package, but if it is in fact based on boost::regex, then it should be trivial to translate these regexes:

"\\s*nameserver\\s+(?<address>.*)"
"\\s*search\\s+(?<domain>.*)"

You need to escape the backslashes when constructing the string that contains the regex. Apart from that, those two regexes don't use any features that boost::regex's Perl-compatible engine can't handle.


std::tr1::regex in GCC is incompelete. std::regex have bugs.

Consider boost::regex.


For what it's worth, if you are using, g++, you are out of luck: Regular expressions are currently not implemented in g++/tr1:

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.tr1

0

精彩评论

暂无评论...
验证码 换一张
取 消