GCC 正则表达式
如何在 GNU G++ / GCC 中使用正则表达式来匹配、搜索和替换子字符串?例如,您可以提供有关 regex_t
和其他内容的教程吗?
谷歌搜索一个多小时没有给我提供任何可以理解的教程或手册。
How do I use regular expressions in GNU G++ / GCC for matching, searching and replacing substrings? E.g. could you provide any tutorial on regex_t
and others?
Googling for above an hour gave me no understandable tutorial or manual.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我强烈建议使用 Boost C++ 正则表达式库。如果您正在开发严肃的 C++,Boost 绝对是您必须考虑的因素。
该库支持 Perl 和 POSIX 正则表达式语法。我个人更喜欢 Perl 正则表达式,因为我相信它们更直观且更容易正确。
http://www.boost。 org/doc/libs/1_46_0/libs/regex/doc/html/boost_regex/syntax.html
但是如果您对这个优秀的库没有任何了解,我建议您从这里开始:
http://www.boost.org/doc/libs/1_46_0 /libs/regex/doc/html/index.html
I strongly suggest using the Boost C++ regex library. If you are developing serious C++, Boost is definitely something you must take into account.
The library supports both Perl and POSIX regular expression syntax. I personally prefer Perl regular expressions since I believe they are more intuitive and easier to get right.
http://www.boost.org/doc/libs/1_46_0/libs/regex/doc/html/boost_regex/syntax.html
But if you don't have any knowledge of this fine library, I suggest you start here:
http://www.boost.org/doc/libs/1_46_0/libs/regex/doc/html/index.html
我在此处找到了答案:
上面的代码将为我们提供
I found the answer here:
The code above will provide us with
手册应该很容易找到:POSIX 正则表达式函数。如果您不明白这一点,我强烈建议您尝试温习 C 和 C++ 技能。
请注意,一旦找到匹配项,实际替换子字符串是一个完全不同的问题,正则表达式函数无法帮助您解决这个问题。
Manuals should be easy enough to find: POSIX regular expression functions. If you don't understand that, I would really recommend trying to brush up on your C and C++ skills.
Note that actually replacing a substring once you have a match is a completely different problem, one that the regex functions won't help you with.