Macthing whole words and not substrings

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Macthing whole words and not substrings

Post by kendall »

Hey guys I'm trying to write a regexp that will match a range of alternate whole words but not match substrings

for e.g.

Code: Select all

/cat|hat|sat/
would match
cat or sat
but not
catalyst or saturday
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Macthing whole words and not substrings

Post by Weirdan »

User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Re: Macthing whole words and not substrings

Post by kendall »

Weirdan wrote:http://www.regular-expressions.info/wordboundaries.html

Code: Select all

 
/\b(cat|hat|sat)\b/
 
aaahhh i see the \b at the end of the pattern...i only had it before the pattern thanks
Post Reply