Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要构建表示 Java 正则表达式的树。java.util.regex.Pattern做这项工作,但它的root字段和Node内部类(及其子类)不可见,所以我无法访问它们。我必须编写自己的解析器并重新实现所有解析逻辑?
java.util.regex.Pattern
root
Node
您可以使用反射来获取这些私有字段,或使用现有的正则表达式/PCRE 解析器:http ://bkiers.github.com/PCREParser 。请注意,PCREParser 库(我是其作者)从未进行过真正的(单元)测试:因此,如果您打算在生产代码中使用它,请针对它进行一些适当的单元测试!:)