C++ 中的正则表达式
我想为正则表达式编写 C++ 库。我知道有很多可用的库,但我想学习正则表达式背后的理论并自己实现它。
有人可以指导我应该从什么开始吗?
I want to write C++ library for Regular Expression. I know there are many libraries available but I want to learn theory behind regular expression and implemented it by myself.
Can anybody please guide on what should I start with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
http://swtch.com/~rsc/regexp/regexp1.html 有一个很好地解释了正则表达式的两种主要方法、它们的权衡,以及如何使更快的方法 (DFA) 在大多数实现无法使用它们的许多情况下可用。
http://swtch.com/~rsc/regexp/regexp1.html has a good explanation of the two major approaches to regular expressions, their trade-offs, and how to make the faster one (DFAs) usable in a lot of cases that most implementations fail to use them for.
《编译器:原理、技术和工具》一书也值得一看,它深入介绍了正则表达式解析背后的技术(以及有关 DFA 和 NDFA 的理论)。它有很好的伪代码示例,可以帮助创建自己的实现
It's also worth looking into book "Compilers: Principles, Techniques, and Tools" that deeply covers techniques behind regular expression parsing (and the theory regarding DFAs and NDFAs). It has good pseudo-code examples that could help in creating own implementation
只要您想编写该库,那么除了参考其他答案提供的优秀资源之外,您还可以探索实现 N3225。
As long as you want to write the library, then in addition to referencing the excellent resources other answers give, you might explore implementing the C++0x specification for regular expressions found in chapter 28 of N3225.
就我而言,这是一本关于正则表达式主题的书。它可能无法让您完全弄清楚如何编写 C++ 库,但对理论的解释非常出色,并且包含许多上下文中正则表达式实际应用的示例。
http://oreilly.com/catalog/9780596528126?green =9514625548&cmp=af-mybuy-9780596528126.IP
As far as I'm concerned, this is THE book on the subject of regular expressions. It may not get you all the way to figuring out how to code up a C++ library, but the explanation of the theory is excellent and it includes a lot of examples for the practical application of regular expressions in many contexts.
http://oreilly.com/catalog/9780596528126?green=9514625548&cmp=af-mybuy-9780596528126.IP
在 Microsoft 实施的 TR1 中,这是下一个报告C++0x 标准,有
库可用。TR1 适用于 Visual 2008,默认情况下适用于 Visual 2010。
当然,只有当您计划在 Windows 平台上编程时,这才有意义。
我不知道 g++ 的 tr1 实现中是否包含
库。我想是的,但我不知道。In the Microsoft implementation of the TR1, which is the report for the next C++0x standard, there is the
<regex>
library available.the TR1 is available for visual 2008, and by default in visual 2010.
But that's interesting only if you plan to program on the windows plateform, of course.
I don't know if g++ includes the
<regex>
library in its tr1 implementation. I guess yes, but I don't know.我用过书 http://www.amazon.com/Compiler-Design-C- Prentice-Hall-软件/dp/0131550454
并在此处实现 http://code.google.com/p/regex/
I have used book http://www.amazon.com/Compiler-Design-C-Prentice-Hall-software/dp/0131550454
and implemented here http://code.google.com/p/regex/