Regex- Is there an IIF equivalent?

  • Thread starter Thread starter Thief_
  • Start date Start date
T

Thief_

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}|&nbsp;)<"

Dim regNumReplies As New RegularExpressions.Regex( _

str2Find, Options:=RegularExpressions.RegexOptions.Singleline)

Return regNumReplies.Matches(str, str2Find).Item(0).Groups(1).ToString

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"?
 
Hi,

Maybe you could use an IIF with regnumreplies.ismatch.

http://msdn.microsoft.com/library/d...regularexpressionsregexclassismatchtopic1.asp

Ken
---------------
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}|&nbsp;)<"

Dim regNumReplies As New RegularExpressions.Regex( _

str2Find, Options:=RegularExpressions.RegexOptions.Singleline)

Return regNumReplies.Matches(str, str2Find).Item(0).Groups(1).ToString

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"?
 
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.
 
Back
Top