Regex question find words that start with special char

P

Peter Proost

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.ToString)
Next


Thanks in advance

Greetz,

Peter
 
E

eBob.com

Peter Proost said:
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.ToString)
Next


Thanks in advance

Greetz,

Peter

See this discussion:

http://groups.google.com/group/micr...df178979f8f9?hl=en&lnk=st&q=#fc7adf178979f8f9

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
 
L

Lloyd Sheen

Peter Proost said:
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.ToString)
Next


Thanks in advance

Greetz,

Peter


@\b\w*\b

Seems that @ is not part of a word. I used tool called Expresso (free) to
get this. If you use it you will see that the regex expands to:

@
First or last character in a word
Alphanumeric, any number of repetitions
First or last character of word

Hope this helps
Lloyd Sheen
 
P

Peter Proost

Hi Bob en Lloyd thanks for your answers, buy using Expresso I found that
just @\w* will also do what I need.

Thanks again,

Greetz,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top