Saideira
Saideira

Reputation: 2414

Bash style pattern matching, expansion and pathname parsing for 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.

Upvotes: 0

Views: 753

Answers (1)

user268396
user268396

Reputation: 11986

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?

Upvotes: 2

Related Questions