From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Difference between \\w and [:word:]? Date: Thu, 07 Jun 2018 19:29:45 -0700 Message-ID: <87r2liovs6.fsf@ericabrahamsen.net> References: <87bmcmmcch.fsf@bsb.me.uk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1528424898 12657 195.159.176.226 (8 Jun 2018 02:28:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 8 Jun 2018 02:28:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 08 04:28:14 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fR78Q-00039P-AZ for geh-help-gnu-emacs@m.gmane.org; Fri, 08 Jun 2018 04:28:14 +0200 Original-Received: from localhost ([::1]:60971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fR7AV-0007Zb-S0 for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jun 2018 22:30:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fR7A5-0007ZJ-UL for help-gnu-emacs@gnu.org; Thu, 07 Jun 2018 22:29:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fR7A2-0002Jd-RW for help-gnu-emacs@gnu.org; Thu, 07 Jun 2018 22:29:57 -0400 Original-Received: from [195.159.176.226] (port=38218 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fR7A2-0002Gh-Gp for help-gnu-emacs@gnu.org; Thu, 07 Jun 2018 22:29:54 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fR77r-0002Ve-Qu for help-gnu-emacs@gnu.org; Fri, 08 Jun 2018 04:27:39 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 41 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:QHUCqkiyRP54co8rma70EKGLgcg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:117029 Archived-At: Ben Bacarisse writes: > Eric Abrahamsen 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