468,101 Members | 1,449 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

.NET Regex Flavor - Word Boundaries

Hi all.

I need to recognize some special keywords in my app. I usually accomplish this task with a regex construction like this…

Expand|Select|Wrap|Line Numbers
  1. \bkeyword\b
…that means “match the keyword if it is preceded and succeeded by a non-alphanumeric character only”.

This time I need to NOT allow a keyword to be matched if it is preceded or succeeded by a $ character, but unfortunately the damned regex engine considers the $ a non-alphanumeric character, so the above construction doesn’t work. I found the next regex construction as a workaround for my problem…

Expand|Select|Wrap|Line Numbers
  1. ([\W-[\$]]|\A)keyword([\W-[\$]]|\z)
…but it is a more complex, hard to understand and maybe slower construction than the original one that uses the \b escape for word boundaries.

Is there any way I can modify the alphanumeric \w and non-alphanumeric \W classes so I can make the $ character an alphanumeric one and then keep using the stylish \b escape for my needs?

Thanks in advance.
Apr 19 '08 #1
0 827

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by David Garamond | last post: by
17 posts views Thread by Mark | last post: by
5 posts views Thread by MrNobody | last post: by
6 posts views Thread by Gary Bond | last post: by
10 posts views Thread by igor.kulkin | last post: by
13 posts views Thread by brad | last post: by
3 posts views Thread by Jeff | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.