Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Regular Expression Woes

Reply
Thread Tools

Regular Expression Woes

 
 
Stephajn Craig
Guest
Posts: n/a
 
      07-17-2003
I'm working for the first time with Regular Expressions. I'm trying to
return a match only when the word I'm looking for is on its own without any
characters before or after it except for punctuation marks.

So here is the pattern I've built so far.

[\s*.*.\w*](England)[\s*.\w*]

This seems to return all matches of England, except that it also returns a
match of _England. The problem is that with the \w switch, an underscore is
considered a word character. But I don't want this, because I'm going to
use the RegExp.Replace function to replace all matches with some
highlighting code. Can anyone help me complete this Search pattern?

--
Stephajn Craig


 
Reply With Quote
 
 
 
 
Chris R. Timmons
Guest
Posts: n/a
 
      07-18-2003
"Stephajn Craig" <(E-Mail Removed)> wrote in
news:OJk#(E-Mail Removed):

> I'm working for the first time with Regular Expressions. I'm
> trying to return a match only when the word I'm looking for is
> on its own without any characters before or after it except for
> punctuation marks.
>
> So here is the pattern I've built so far.
>
> [\s*.*.\w*](England)[\s*.\w*]
>
> This seems to return all matches of England, except that it also
> returns a match of _England. The problem is that with the \w
> switch, an underscore is considered a word character. But I
> don't want this, because I'm going to use the RegExp.Replace
> function to replace all matches with some highlighting code.
> Can anyone help me complete this Search pattern?
>


Stephajn,

Use the \b (or "word boundary") escape sequence:

\bEngland\b

This will match "England", but not "_England" or "England_".

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Regular expression woes Mark (News) Javascript 23 02-08-2005 10:42 PM
Regular expression woes Mark (News) Perl Misc 23 02-08-2005 10:42 PM
Regular Expression Woes =?Utf-8?B?SmltIE1hY2U=?= ASP .Net 0 05-25-2004 03:11 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments