473,473 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regular Expression Woes

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
Nov 17 '05 #1
1 1411
"Stephajn Craig" <s.*****@NOSPAMfunsunvacations.com> wrote in
news:OJ**************@TK2MSFTNGP10.phx.gbl:
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/
Nov 17 '05 #2

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

Similar topics

1
by: Rob Pridham | last post by:
Hi. I'm trying to use ereg_replace to turn some text based hyperlinks into WML code. WML is similar to HTML, except for mobile phones and very strict. That means that there's some characters you...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
23
by: Mark (News) | last post by:
I'm not really sure where to post this question as it covers so many platforms, but as the platform isn't relevant, here goes... I'm trying to (pulling my hair out more like) construct a regular...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
0
by: Jim Mace | last post by:
I have been racking my brain trying to figure out a regular expression that will replace all of the characters in a string except the very first character from uppercase to lower case. Any ideas. I...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
9
by: Mark Rae | last post by:
Hi, This time, I'm looking for a regular expression which says "the string must contain exactly seven or exactly eight digits" e.g. 123456 fails 1234567 passes 12345678 passes 123456789...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.