473,587 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex question find words that start with special char

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
Jun 27 '08 #1
3 2900
"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

Jun 27 '08 #2

"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

@\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

Jun 27 '08 #3
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
Lloyd Sheen wrote:
>
"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


@\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
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5717
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning is to improve, but not to prove.
7
1903
by: Razzie | last post by:
Hey all, Decided to give a shot at Regular expressions - need a bit of help :) I can't seem to find the right regex for matching words like "*test*" or *somevalue*" - in short, all words starting and ending with a *. I tried things like string regex = @"(^*\|*^)"); but it still doesn't work completely (matches on "*test" too for...
6
4783
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search string. It's actually the input string into a Microsoft Index Server search. The string will consist of words, perhaps enclosed in quotes or...
17
3956
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher http://forta.com/books/0672325667/
2
1366
by: .NET Developer | last post by:
Hello, I'm trying to write a RegEx that will find all occurances of a particular type of HTML anchor <a> element in a big block of HTML. Here are the pattern requirements - they consist of certain attributes being present, basically: must start with "<a" followed by 1 or more white-space characters then, before the closing tag ">" it must...
11
3090
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend a hand? import regsub
1
4208
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD: (there is a WORD in ( my string WORD )) and * WORD * to (find WORD) and * WORD * Should give me the to word between star (star ar not part of string)
10
3854
by: igor.kulkin | last post by:
I have a small utility program written in Python which works pretty slow so I've decided to implement it in C. I did some benchmarking of Python's code performance. One of the parts of the program is using Python's standard re (regular expressions) module to parse the input file. As Python's routines to read from the file and regular...
7
2051
by: Nightcrawler | last post by:
Hi all, I am trying to use regular expressions to parse out mp3 titles into three different groups (artist, title and remix). I currently have three ways to name a mp3 file: Artist - Title Artist - Title (Remix) Artist - Title
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.