By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,821 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,821 IT Pros & Developers. It's quick & easy.

Regex- Is there an IIF equivalent?

P: n/a
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.Singlelin e)

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"?
--
|
+-- Thief_
|
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Hi,

Maybe you could use an IIF with regnumreplies.ismatch.

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

Ken
---------------
"Thief_" <th****@hotmail.com> wrote in message
news:uD****************@TK2MSFTNGP14.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}|&nbsp;)<"

Dim regNumReplies As New RegularExpressions.Regex( _

str2Find, Options:=RegularExpressions.RegexOptions.Singlelin e)

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"?
--
|
+-- Thief_
|

Nov 21 '05 #2

P: n/a
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]" <vb***@bellsouth.net> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
Hi,

Maybe you could use an IIF with regnumreplies.ismatch.

http://msdn.microsoft.com/library/de...atchtopic1.asp
Ken
---------------
"Thief_" <th****@hotmail.com> wrote in message
news:uD****************@TK2MSFTNGP14.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}|&nbsp;)<"

Dim regNumReplies As New RegularExpressions.Regex( _

str2Find, Options:=RegularExpressions.RegexOptions.Singlelin e)

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"?
--
|
+-- Thief_
|

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.