Jono
Jono

Reputation: 18108

regular expression that has a Or condition?

is it possible to create a OR condition in a regular expression.

i am trying to locate a match that contains a list of file names of this type of pattern

1st case

xxxxx-hello.file

or 2nd case

xxxx-hello-unasigned.file

this reg > -hello.file works fine for the first case but is their a way to check the second case too?

i do not want to create two regex and want to combine the two cases if possible.

Thanks.

Upvotes: 0

Views: 94

Answers (4)

Jono
Jono

Reputation: 18108

I fixed this myself using multiple include in a fileset.

this did the trick for me. no idea why the reg ex diddnt work.

<fileset dir="bin" >
                <include name="welcome-hello-unasigned.file" />
                <include name="welcome-hello.file" />
            </fileset>

Upvotes: 0

Joseph Silber
Joseph Silber

Reputation: 219938

Make the group optional:

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

If performance is an issue, you should set that group as a non-capturing group:

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

If you want it to only match that exact amount of characters, you should use a pipe for your OR case:

.{5}-hello[.]file|.{4}-hello-unasigned[.]file

Upvotes: 7

Kevin Bowersox
Kevin Bowersox

Reputation: 94459

*-hello.file|*-hello-unassigned.file

Use |

Upvotes: 0

Explosion Pills
Explosion Pills

Reputation: 191749

Just use |:

.*-hello.file|.*-hello-unasigned.file

Upvotes: 0

Related Questions