[TxMt] find with "match entire word"
Jay Soffian
jay-txmt at soffian.org
Wed Jul 18 17:02:14 UTC 2007
On Jul 18, 2007, at 12:37 PM, Craig Schmidt wrote:
> I've been trying to bracket the variable with the "non word
> character", so I search for the regular expression \Wx\W
>
> This excludes xbar, and foox. However, this isn't quite the same as
> matching just the word, as the find dialog also selects the
> previous and next character, matching the \W. I can't use it in a
> replace, for example. Is there some cleaner way of doing this?
You need to employ a zero-width assertion/anchor. This is a way of
anchoring/matching w/o including the match itself. Examples are (from
the Oniguruma help):
^ beginning of the line
$ end of the line
\b word boundary
\B not word boundary
\A beginning of string
\Z end of string, or before newline at the end
\z end of string
There is also a general mechanism:
(?=subexp) look-ahead
(?!subexp) negative look-ahead
(?<=subexp) look-behind
(?<!subexp) negative look-behind
The perl regular expression engine is sufficiently similar to
Oniguruma that you may find the "perlre" man page helpful. I also
highly recommend Mastering Regular Expressions.
To answer your specific question, you probably want \bx\b
j.
More information about the textmate
mailing list