0

是否可以在正则表达式中创建 OR 条件。

我正在尝试查找包含此类模式的文件名列表的匹配项

第一种情况

xxxxx-hello.file

或第二种情况

xxxx-hello-unasigned.file

这个 reg >-hello.file适用于第一种情况,但他们也是检查第二种情况的方法吗?

我不想创建两个正则表达式,如果可能的话想结合这两种情况。

谢谢。

4

4 回答 4

7

使组可选:

.*-hello(-unasigned)?[.]file

如果性能是一个问题,您应该将该组设置为非捕获组:

.*-hello(?:-unasigned)?[.]file

如果您希望它只匹配确切数量的字符,您应该为您的 OR 案例使用管道:

.{5}-hello[.]file|.{4}-hello-unasigned[.]file
于 2013-01-29T17:23:34.387 回答
0

我在文件集中使用多个包含自己修复了这个问题。

这对我有用。不知道为什么 reg ex 没有工作。

<fileset dir="bin" >
                <include name="welcome-hello-unasigned.file" />
                <include name="welcome-hello.file" />
            </fileset>
于 2013-01-31T09:18:40.407 回答
0

只需使用|

.*-hello.file|.*-hello-unasigned.file
于 2013-01-29T17:23:31.670 回答
0
*-hello.file|*-hello-unassigned.file

使用 |

于 2013-01-29T17:23:39.800 回答