[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Newbie: Word matching?



At 21.20 97/2/21, h0000268 wrote:
>The first regular expression /[^ ]$String[$ ]/ won't work and I have no
>idea why. I even tried to replace the spaces with \s, but still nothing
>happens... I am trying to search for the beginning of a line or a space,
>followed by the string, followed by an end of line or space.

Use the \b metacharacter.  It searches word boundaries:

\bword\b would find "word" but not "password".

Also, the [$ ] and [^ ] do not do what you think they do.  The ^ negates a
character class, and the $ is simply seen as an actual character in the
class.

BTW, this is a general Perl question, not a MacPerl question, and belongs
in a general Perl newgroup or list.

Hope this helps,

#================================================================
Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6