Regex OR match ???

Discussion in 'ASP .Net' started by jason@cyberpine.com, May 27, 2004.

  1. Guest

    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.
     
    , May 27, 2004
    #1
    1. Advertising

  2. wrote in
    news::

    > 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

    --
    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.
    http://www.crtimmonsinc.com/
     
    Chris R. Timmons, May 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hiwa
    Replies:
    0
    Views:
    653
  2. Victor
    Replies:
    2
    Views:
    661
    Victor
    May 17, 2004
  3. ekzept
    Replies:
    0
    Views:
    390
    ekzept
    Aug 10, 2007
  4. Replies:
    3
    Views:
    809
    Reedick, Andrew
    Jul 1, 2008
  5. John Gordon
    Replies:
    13
    Views:
    503
    Ian Kelly
    Dec 20, 2011
Loading...

Share This Page