From: Greg Millam Date: 2002-12-19T13:38:23+09:00 Subject: Re: How to include some text and exclude other in one regular expression? On Thu, 19 Dec 2002, Usano wrote: > I would like to match "file 1 of 2" or "1 of 2", but not "day 1 of 2". > > I can match "file 1 of 2" with... > > /(file)? *\d+ *of *\d+/ > > I wonder if (in the same regex), I can prevent a match to "day 1 of > 2"? The above expression will match this by just ignoring the word > "day". > > Can this be done? /^(file)?\s*(\d+)\s*of\s*(\d+)$/ \s is any white space character. adding ^ and $ to the beginning and end of the expression make it match the entire string. since /1 or 2/ will match "day 1 or 2" "file 1 or 2" or "In 2002, 1 or 2 people answered this email" /^1 or 2$/ makes it match only "1 or 2", with nothing before or after. Hope this helps, Greg. > > Thank you, > - Usano > -- Greg Millam walker at deafcode.com