Java 的 Bash 风格模式匹配、扩展和路径名解析
我的项目具有树状结构的对象,需要实现通配符和模式匹配以及访问所述对象的路径扩展。此功能与 Bash 的命令行功能非常相似。
示例查询可能是
find .\[NC]*\Hospitals\Addresses\*
这将递归搜索当前节点下方的所有节点,以查找位于名称开头的州的所有医院的地址带有 N 或 C(即内华达州、内布拉斯加州、加利福尼亚州等)。
是否有任何现有的且相当轻量级的库或框架可供Java执行此操作?我不想重新发明轮子。
My project has objects structured in a tree and needs to implement wild card and pattern matching, path expansion for accessing the said objects. This functionality is very similar to what Bash does with its command line.
A sample query might be
find .\[NC]*\Hospitals\Addresses\*
This would recursively search all nodes below the current one for the Addresses of all hospitals that are located in the states which name starts with N or C (ie Nevada, Nebraska, California, etc).
Are there any existing and fairly lightweight libraries or frameworks for Java to do this? I dont want to reinvent the wheel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以选择使用 Java 7,它内置了 glob: http://download.oracle.com/javase/tutorial/essential/io/fileOps.html
如果没有,这个 StackOverflow 问题 &答案可能有用: 是否有相当于“glob”类型模式的 java.util.regex?
If you have the option to use Java 7, it has glob built in: http://download.oracle.com/javase/tutorial/essential/io/fileOps.html
If not, this StackOverflow question & answers may prove useful: Is there an equivalent of java.util.regex for "glob" type patterns?