/\b(K|S)\d{2}?$expression\b/;
That will match a string like ".NO.K74apmd" because it is simply looking for a word boundary before the K or S. You should anchor it to the beginning of the string instead.
/^(K|S)\d{2}?$expression\b/;Also, that \b at the end of the pattern probably isn't really what you want. It might match something like "K74apmd.orig" for example. You probably mean to anchor that to the end of the string.
/^(K|S)\d{2}?$expression$/;Oh, and a couple other things too... Although it won't really result in a noticeable performance hit in this case, as a matter of style you should probably avoid alternation when a character class will do. Finally, that ? is telling your {2} to be non-greedy, but a non-greedy absolute quantifier doesn't make much sense. It's like saying, "match exactly 2 but as few as possible."
Those changes leave us with:
/^[KS]\d{2}$expression$/;-sauoq "My two cents aren't worth a dime.";
In reply to Re: Getting a Regex Not to Match Again
by sauoq
in thread Getting a Regex Not to Match Again
by dru145
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |