4

我想将正则表达式转换为 glob

我在看jakarta oro但我找不到适合我需要的方法。它编译正则表达式并返回其 glob 等价物

它们都是Type-3语法,所以理论上应该是可能的。

不幸的是,我受到使用 JDK5 的限制。

4

1 回答 1

0

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.

于 2016-04-15T01:25:20.710 回答