Mark Findlay wrote:
I am trying to figure out how to set up my reg exp search so that the search
will only match on the exact word.
Here is the current problem code:
Word1 = "RealPlayer.exe"
Word2 = "Player.exe"
RegExp re = Word2;
if (re.Find(Word1))
{
bFound = TRUE;
}
Currently the bFound is set to TRUE since "Player.exe" is found within
"RealPlayer.exe". But I only want bFound to be TRUE is if the entire word
matches.
Can anyone assist with the correct syntax?
Many Thanks!
Mark
Word1 = "^Player.exe"; // "^" denotes it must match from the start of line
// or
Word1 = "^Player.exe$";
// "^" denotes it must match from the start of line
// "$" denotes it must match the end of line, in other words, an exact match
of course, as has been already pointed out, a regex match against "^...$" is the
same as testing if the two strings are equal.
Some regex references:
<url:
http://devedge.netscape.com/library/...ce/frames.html
/>
<url:
http://msdn.microsoft.com/library/en...asp?frame=true
/>
I prefer the Netscape one, because, although older, everything mentioned there
works in newer browsers. Whereas some of the newer features to Javascript (such
as "?" non-greedy and "(?:pattern)" non-capturing match) only work in the most
modern browsers.
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html