Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

basic regex question

0 views
Skip to first unread message

Jeff

unread,
May 17, 2007, 12:52:01 AM5/17/07
to

...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


--
Posted via a free Usenet account from http://www.teranews.com

Andrew Morton

unread,
May 17, 2007, 4:42:02 AM5/17/07
to
Jeff wrote:
> ...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


rowe_newsgroups

unread,
May 17, 2007, 10:26:34 AM5/17/07
to

Off the top of my head:

Imports System.Text.RegularExpressions

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

Thanks,

Seth Rowe

Jeff

unread,
May 18, 2007, 6:33:26 PM5/18/07
to

"Jeff" <no...@nothingX.com> wrote in message
news:464bd328$0$16300$8826...@free.teranews.com...
>


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

rowe_newsgroups

unread,
May 18, 2007, 9:09:09 PM5/18/07
to
On May 18, 6:33 pm, "Jeff" <no_...@george.com> wrote:
> "Jeff" <n...@nothingX.com> wrote in message

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

Jeff

unread,
May 19, 2007, 12:39:29 PM5/19/07
to

"rowe_newsgroups" <rowe_...@yahoo.com> wrote in message
news:1179536949.5...@n59g2000hsh.googlegroups.com...

> 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.

0 new messages