[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.
- Difference between \\w and [:word:]?, Eric Abrahamsen, 2018/06/07
- Re: Difference between \\w and [:word:]?,
Ben Bacarisse <=
- Re: Difference between \\w and [:word:]?, Eric Abrahamsen, 2018/06/07
- Re: Difference between \\w and [:word:]?, Robert Pluim, 2018/06/08
- Re: Difference between \\w and [:word:]?, Yuri Khan, 2018/06/08
- Re: Difference between \\w and [:word:]?, Eric Abrahamsen, 2018/06/08
- Re: Difference between \\w and [:word:]?, Stefan Monnier, 2018/06/09
- Re: Difference between \\w and [:word:]?, Eric Abrahamsen, 2018/06/09