"Peter Proost" <pp*****@nospam .hotmail.comwro te in message
news:OS******** ******@TK2MSFTN GP04.phx.gbl...
Hi group first of all I need to say that I almost never use regex hence my
question may be stupid.
I'm using regex to find all words that start with an @ in a string.
But the regex that I figured doesn't work. can anyone help me.
Dim myReg As New Regex("\b@\w*\b ")
Dim mcCol As MatchCollection
Dim mc As Match
mcCol = myReg.Matches(" @param1 @param2 @test +56 -23 *25)
'I would like to get @param1 and @param2 and @test
For Each mc In mcCol
MsgBox(mc.ToStr ing)
Next
Thanks in advance
Greetz,
Peter
See this discussion:
http://groups.google.com/group/micro...7adf178979f8f9
To summarize, you are looking for @\w* delimited by word boundaries, but @
is not a word character. So, it seems, you cannot have a word boundary
immediately preceding a non-word character. Or, another way to look at it,
\b does not just represent a set of word separating characters but a set of
word separating characters IN CONTEXT.
Regular expressions are very useful in many, many programming situations.
So unless you are absolutely certain that you will never need to use another
regular expression I recommend that you do two things: 1) play with this a
bit. For example delete the \b from the beginning and end of your
expression.. Also, change every @ in the code you posted to an x, with the
word boundary delimiters in place. And 2) get Expresso from Ultrapico. In
fact, you might want to get Expresso first.
Good Luck, Bob