Regex- Is there an IIF equivalent?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thief_

    #1

    Regex- Is there an IIF equivalent?

    I'm using the following code to extract a number, upto 3 digits long, from a
    web page:

    Dim str2Find As String = ">(\d{0,3}|&nbs p;)<"

    Dim regNumReplies As New RegularExpressi ons.Regex( _

    str2Find, Options:=Regula rExpressions.Re gexOptions.Sing leline)

    Return regNumReplies.M atches(str, str2Find).Item( 0).Groups(1).To String

    If the number does not exist, it returns "&nbsp;". Is there a way, using
    RegEx, to return either the digits found, or if "&nbsp;" is found, return
    "0"?


    --
    |
    +-- Thief_
    |


  • Ken Tucker [MVP]

    #2
    Re: Regex- Is there an IIF equivalent?

    Hi,

    Maybe you could use an IIF with regnumreplies.i smatch.

    http://msdn.microsoft.com/library/de...atchtopic1.asp

    Ken
    ---------------
    "Thief_" <thief_@hotmail .com> wrote in message
    news:uDviP%23wk FHA.2608@TK2MSF TNGP14.phx.gbl. ..
    I'm using the following code to extract a number, upto 3 digits long, from a
    web page:

    Dim str2Find As String = ">(\d{0,3}|&nbs p;)<"

    Dim regNumReplies As New RegularExpressi ons.Regex( _

    str2Find, Options:=Regula rExpressions.Re gexOptions.Sing leline)

    Return regNumReplies.M atches(str, str2Find).Item( 0).Groups(1).To String

    If the number does not exist, it returns "&nbsp;". Is there a way, using
    RegEx, to return either the digits found, or if "&nbsp;" is found, return
    "0"?


    --
    |
    +-- Thief_
    |



    Comment

    • Thief_

      #3
      Re: Regex- Is there an IIF equivalent?

      That solution will not work because the outcome of the IsMatch property will
      be true if either a number or "&nbsp;" is found. I think, for now at least,
      I'll add a VB.NET IIF in the next line to change the value.

      I just thought it would be cool to do it all in RegEx. Thanks.

      --
      |
      +-- Thief_
      |

      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:ek0QJkxkFH A.2792@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi,
      >
      > Maybe you could use an IIF with regnumreplies.i smatch.
      >
      >[/color]
      http://msdn.microsoft.com/library/de...atchtopic1.asp[color=blue]
      >
      > Ken
      > ---------------
      > "Thief_" <thief_@hotmail .com> wrote in message
      > news:uDviP%23wk FHA.2608@TK2MSF TNGP14.phx.gbl. ..
      > I'm using the following code to extract a number, upto 3 digits long, from[/color]
      a[color=blue]
      > web page:
      >
      > Dim str2Find As String = ">(\d{0,3}|&nbs p;)<"
      >
      > Dim regNumReplies As New RegularExpressi ons.Regex( _
      >
      > str2Find, Options:=Regula rExpressions.Re gexOptions.Sing leline)
      >
      > Return regNumReplies.M atches(str, str2Find).Item( 0).Groups(1).To String
      >
      > If the number does not exist, it returns "&nbsp;". Is there a way, using
      > RegEx, to return either the digits found, or if "&nbsp;" is found, return
      > "0"?
      >
      >
      > --
      > |
      > +-- Thief_
      > |
      >
      >
      >[/color]


      Comment

      Working...