help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Difference between \\w and [:word:]?


From: Ben Bacarisse
Subject: Re: Difference between \\w and [:word:]?
Date: Fri, 08 Jun 2018 00:00:14 +0100

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Can someone explain to me what's happening here? What's the difference
> between \\w and [:word:], inside and outside of a bracket construction?
>
> (setq case-fold-search nil)
> (string-match-p "[:word:]" "P") => nil

This is the same as (string-match-p "[wrdo:]" "P").  It's just a
collection of characters to be matched.

> (string-match-p "[[:word:]]" "P") => 0

This looks for a member of the character class [:word:] in the string.
It finds it (case-insensitively) at position 0.  Technically, the
current character class table determines what is a word-constituent.

> (string-match-p "\\w" "P") => 0

This does the same.

> (string-match-p "[\\w]" "P") = nil

And this is just a normal character class match looking for either a w
or a \.

I can never quite decide if it's good or bad that the named character
classes use the same [...] syntax.  [:digit:] is just a plain character
set with a duplicated : and i in it.  It only becomes a named class
inside a character set.

-- 
Ben.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]