Is there a standard (preferably Apache Commons or similarly non-viral) library for doing "glob" type matches in Java? When I had to do similar in Perl once, I just changed all the ".
" to "\.
", the "*
" to ".*
" and the "?
" to ".
" and that sort of thing, but I'm wondering if somebody has done the work for me.
Similar question: Create regex from glob expression
The pattern rules for glob are not regular expressions. Instead, they follow standard Unix path expansion rules. There are only a few special characters: two different wild-cards, and character ranges are supported. The patterns rules are applied to segments of the filename (stopping at the path separator, /).
A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data. The java.util.regex package primarily consists of the following three classes −
What is a Glob? In programming, glob is a pattern using wildcards to specify filenames. For example, *. java is a simple and trivial glob. It specifies all files with extension 'java'.
What are globs? Globs, also known as glob patterns are patterns that can expand a wildcard pattern into a list of pathnames that match the given pattern.
Globbing is also planned for implemented in Java 7.
See FileSystem.getPathMatcher(String)
and the "Finding Files" tutorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With