Re: Regexp: \m and [^[:alnum:]_] are not equivalent



"Francois Vogel" <fsvogelnew5NOSPAM@xxxxxxx> writes:

> In regexps, the \m escape is advertised to match at the beginning of a word.

Yes.


> What is defined as a word in the re_syntax man page is an alnum or an
> underscore, i.e. [[:alnum:]_]

Yes.

> From that I deduce I can match at the beginning of a word if I use the
> negative of the above, i.e. [^[:alnum:]_]

No! That is how you match anything that is not a word!

\m is the zero-length match of the boundary between non-word and
word. If you want to simulate it by other means, see the lookahead
(?=[[:alnum:]_]). There's no look-behind syntax though, so I don't
know how to exactly duplicate the behaviour of \m.


--
Donald Arseneau asnd@xxxxxxxxx
.



Relevant Pages