Regex OR match ???

J

jason

I have following two regex expressions. I am trying to match in the
event that *EITHER* is found - combining with an OR. However, I can't
seem to get the syntax right.

Dim regexp2 as Regex = New Regex("a(.+)b", RegexOptions.IgnoreCase)
Dim regexp3 as Regex = New Regex("c(.+)d", RegexOptions.IgnoreCase)


The below code does NOT work as the compiler does not like that OR:

Dim regexp2 as Regex = New Regex("a(.+)b" or "c(.+)d",
RegexOptions.IgnoreCase)

Dim objMatch as Match
dim z as string

For Each objMatch in regexp2.Matches(x)
response.write(objMatch.ToString())
response.write("<br>")
Next


Thanks for any help or information.
 
C

Chris R. Timmons

(e-mail address removed) wrote in
I have following two regex expressions. I am trying to match in
the event that *EITHER* is found - combining with an OR.
However, I can't seem to get the syntax right.

Dim regexp2 as Regex = New Regex("a(.+)b",
RegexOptions.IgnoreCase) Dim regexp3 as Regex = New
Regex("c(.+)d", RegexOptions.IgnoreCase)


The below code does NOT work as the compiler does not like that
OR:

Dim regexp2 as Regex = New Regex("a(.+)b" or "c(.+)d",
RegexOptions.IgnoreCase)

Dim objMatch as Match
dim z as string

For Each objMatch in regexp2.Matches(x)
response.write(objMatch.ToString())
response.write("<br>")
Next


Thanks for any help or information.

Jason,

The vertical bar (|) is the regex "or" operator:

a(.+)b|c(.+)d
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top