basic regex question

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

....hoping someone can help someone still new to vb.net 2005 with something
new to him.

....been successfully using the regular expression validators from the
toolbox, but now I have need to do something strictly with code.

....need to determine if a stored string matches a stored regular expression.

....not sure what to search under for an example to give me a starting point.
I can figure out the actual expression syntax and the rest if someone can
get me started.

e.g., something along these lines

dim myregex as new regex
if mystoredstring = regex then
DoAllKindsOfStuff()
end if

Thanks

jeff
 
Jeff said:
...hoping someone can help someone still new to vb.net 2005 with
something new to him.

...been successfully using the regular expression validators from the
toolbox, but now I have need to do something strictly with code.

...need to determine if a stored string matches a stored regular
expression.

I think you're looking for the RegEx.IsMatch method.

Andrew
 
...hoping someone can help someone still new to vb.net 2005 with something
new to him.

...been successfully using the regular expression validators from the
toolbox, but now I have need to do something strictly with code.

...need to determine if a stored string matches a stored regular expression.

...not sure what to search under for an example to give me a starting point.
I can figure out the actual expression syntax and the rest if someone can
get me started.

e.g., something along these lines

dim myregex as new regex
if mystoredstring = regex then
DoAllKindsOfStuff()
end if

Thanks

jeff

Off the top of my head:

Imports System.Text.RegularExpressions

If Regex.IsMatch(mystoredstring, myregexpattern) Then
DoAllKindsOfStuff()
end if

Thanks,

Seth Rowe
 
Okay, now I'm really confused.

I got this figured out somewhat, but either there is a major bug somewhere,
or I don't understand something fundamental (and it is likely the latter)

If I uses a regular expression validator from the toolbox and the expression
[a-zA-Z1-9]* it will properly match letters and numbers.

The exact same regular expression in the code below fails and matches
everything. Something seems to be going on everytime that I enter a reg
expression with a bracket - it will work with the toolbox validator, but not
when I use all vb code.

Can someone explain? I'm lost.

Dim regexobj As Regex = New Regex("[a-zA-Z1-9]*")

If RegexObj.IsMatch(TBUser.Text) = False Then
 
Okay, now I'm really confused.

I got this figured out somewhat, but either there is a major bug somewhere,
or I don't understand something fundamental (and it is likely the latter)

If I uses a regular expression validator from the toolbox and the expression
[a-zA-Z1-9]* it will properly match letters and numbers.

The exact same regular expression in the code below fails and matches
everything. Something seems to be going on everytime that I enter a reg
expression with a bracket - it will work with the toolbox validator, but not
when I use all vb code.

Can someone explain? I'm lost.

Dim regexobj As Regex = New Regex("[a-zA-Z1-9]*")

If RegexObj.IsMatch(TBUser.Text) = False Then

I'm just guessing - but it may have to do with the RegexOptions you
are using - try experimenting with them and see if it makes a
difference.

Also, you might want to post some sample text and the complete regex
pattern that is causing the problem - that way I can take a better
look at it.

Thanks,

Seth Rowe
 
rowe_newsgroups said:
I'm just guessing - but it may have to do with the RegexOptions you
are using - try experimenting with them and see if it makes a
difference.

Also, you might want to post some sample text and the complete regex
pattern that is causing the problem - that way I can take a better
look at it.

Thanks,

Seth Rowe


Okay, I think that I have much of this figured out. The validator through
the toolbox (is there a good way to say this?) does not evaluate empty
textbox values regardless of the regex expression, while the hardcoded
version works essentially like all of the instructions that I see about
using regex. I didn't pick up on that initially, and that was causing the
confusion.

I think that I have it going now.

Thanks for the help.
 
Back
Top