How to convert regex to extglob expression?

I would like to convert regex to glob

I have looked at jakarta oro But I cannot find a method that suits my needs. That it compiles the regex and returns its glob equivalent

They are both type 3 grammars, so in theory this should be possible.

I am unfortunately limited with JDK5.

+3


source to share


1 answer


extglob can match several regex constructs ( pattern-list

- changelog):

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, also:



??????????????    [^abc]
??????????????    \1
??????????????    most look arounds

      

Assuming all the constructs in the regular expression have extglob equivalents, one could convert them to the extglob form. It will be tricky because the regex is represented by CFG. And you are using Java, which forces you to use hidden escape run \\

.

Why not just use another bash utility that supports regular expressions? Like this .

0


source







All Articles