Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Trying to combine two scripts and open in a new window


rocknbil - 4:52 pm on Mar 15, 2012 (gmt 0)


I don't know, does it work or not? :-)



find a certain word on my webpage. It is a unique word


But . . . I have a feeling it still won't match exactly, and may still find other 17 character words (if there are any).

Examine what it does.

^ ... $ = the string you're searching STARTS WITH (^) and ENDS WITH $. If you're searching a whole page, I'm guessing the answer is "no, it doesn't work." This means the whole page must start and end with your pattern and contain nothing else.

/^abc$/ will match 'abc' but not " learn your abc's"

() = probably not needed, this is to group patterns and/or store the match in special variables, i.e. (this)(that) will have "this" in $1 and "that" in $2 (if a match is found.)

[] - character class - "if the pattern contains any of these characters"

a-zA-Z - match any letters. This is more efficient with the case insensitive modifier "i" (but works the same, so is OK . . .)

0-9 = match any digit, identical to \d

_- = characters to match - be cautious with the dash, as you can see above when in a character class it's often used to define a range, so I just always escape it (and the underscore as well. Probably not needed but that's what I do.)

{17} = a quantifier, match *exactly* 17 of the preceding characters.

so, all that being said, a more efficient version might be


/[a-z\d\_\-]{17}/i

But as mentioned, I doubt that's what you're after and may return other 17 character strings. If it's a unique word, why not just match the exact pattern?

var pat = '/aybe_cee-dee_effg/i';


Thread source:: http://www.webmasterworld.com/javascript/4428738.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com