From: Ben Bacarisse <ben.usenet@bsb.me.uk>
To: help-gnu-emacs@gnu.org
Subject: Re: Difference between \\w and [:word:]?
Date: Fri, 08 Jun 2018 00:00:14 +0100 [thread overview]
Message-ID: <87bmcmmcch.fsf@bsb.me.uk> (raw)
In-Reply-To: mailman.1434.1528399150.1292.help-gnu-emacs@gnu.org
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.
next parent reply other threads:[~2018-06-07 23:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1434.1528399150.1292.help-gnu-emacs@gnu.org>
2018-06-07 23:00 ` Ben Bacarisse [this message]
2018-06-08 2:29 ` Difference between \\w and [:word:]? Eric Abrahamsen
2018-06-08 9:16 ` Robert Pluim
2018-06-08 9:24 ` Yuri Khan
2018-06-08 15:05 ` Eric Abrahamsen
2018-06-09 23:36 ` Stefan Monnier
2018-06-10 2:05 ` Eric Abrahamsen
2018-06-07 19:18 Eric Abrahamsen
2018-06-07 20:24 ` Robert Pluim
2018-06-07 21:35 ` Eric Abrahamsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bmcmmcch.fsf@bsb.me.uk \
--to=ben.usenet@bsb.me.uk \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.