[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Difference between \\w and [:word:]?
From: |
Eric Abrahamsen |
Subject: |
Re: Difference between \\w and [:word:]? |
Date: |
Thu, 07 Jun 2018 19:29:45 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> 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.
Yeah, I did figure that out once I read the manual properly.
>> (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.
It definitely felt a little weird writing something like
"\\w[[:word:]-']+", where we're required to use two different notations
for the same match.
Thanks,
Eric
- Difference between \\w and [:word:]?, Eric Abrahamsen, 2018/06/07
- Re: Difference between \\w and [:word:]?, Ben Bacarisse, 2018/06/07
- Re: Difference between \\w and [:word:]?,
Eric Abrahamsen <=
- 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