Reputation: 718
I'd like to convert regular expression into glob
I was looking on jakarta oro But i can't find method that suits my needs. That it compiles regular expression and returns its glob equivalent
They are both Type-3 grammars, so in theory it should be possible.
I am unfortunatelly limited by using JDK5.
Upvotes: 4
Views: 1723
Reputation: 6173
extglob can match a number of regex constructs (pattern-list
is a list of alterations):
extglob regex
-------------- -----------------
? [^/]
* [^/]*
. \.
** .
?(pattern-list) (pattern-list)?
*(pattern-list) (pattern-list)*
+(pattern-list) (pattern-list)+
@(pattern-list) (pattern-list)
!(pattern-list) (?!pattern-list)
There are some things that regex does that cannot be done in extglob, as far as I know, too:
?????????????? [^abc]
?????????????? \1
?????????????? most look arounds
Assuming all of the constructs in the regex have extglob equivalents, it would be possible to convert it to extglob form. It would be difficult, because regexes are represented by a CFG. And you're using Java, which forces you to use the evil escaped escape \\
.
Why not just use a different bash utility that supports regexes? Like this.
Upvotes: 0