all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Difference between \\w and [:word:]?
@ 2018-06-07 19:18 Eric Abrahamsen
  2018-06-07 20:24 ` Robert Pluim
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Abrahamsen @ 2018-06-07 19:18 UTC (permalink / raw)
  To: help-gnu-emacs

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
(string-match-p "[[:word:]]" "P") => 0
(string-match-p "\\w" "P") => 0
(string-match-p "[\\w]" "P") = nil




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-07 19:18 Eric Abrahamsen
@ 2018-06-07 20:24 ` Robert Pluim
  2018-06-07 21:35   ` Eric Abrahamsen
  0 siblings, 1 reply; 10+ messages in thread
From: Robert Pluim @ 2018-06-07 20:24 UTC (permalink / raw)
  To: help-gnu-emacs

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
> (string-match-p "[[:word:]]" "P") => 0
> (string-match-p "\\w" "P") => 0
> (string-match-p "[\\w]" "P") = nil

Consider

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

Robert




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-07 20:24 ` Robert Pluim
@ 2018-06-07 21:35   ` Eric Abrahamsen
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Abrahamsen @ 2018-06-07 21:35 UTC (permalink / raw)
  To: help-gnu-emacs

Robert Pluim <rpluim@gmail.com> 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
>> (string-match-p "[[:word:]]" "P") => 0
>> (string-match-p "\\w" "P") => 0
>> (string-match-p "[\\w]" "P") = nil
>
> Consider
>
> (string-match-p "[\\w]" "w") => ?

Oh, ha.

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

And my other confusion (about character classes) was cleared up by
reading the manual more carefully.

Thanks,
Eric




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
       [not found] <mailman.1434.1528399150.1292.help-gnu-emacs@gnu.org>
@ 2018-06-07 23:00 ` Ben Bacarisse
  2018-06-08  2:29   ` Eric Abrahamsen
  0 siblings, 1 reply; 10+ messages in thread
From: Ben Bacarisse @ 2018-06-07 23:00 UTC (permalink / raw)
  To: help-gnu-emacs

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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-07 23:00 ` Difference between \\w and [:word:]? Ben Bacarisse
@ 2018-06-08  2:29   ` Eric Abrahamsen
  2018-06-08  9:16     ` Robert Pluim
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Abrahamsen @ 2018-06-08  2:29 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-08  2:29   ` Eric Abrahamsen
@ 2018-06-08  9:16     ` Robert Pluim
  2018-06-08  9:24       ` Yuri Khan
  0 siblings, 1 reply; 10+ messages in thread
From: Robert Pluim @ 2018-06-08  9:16 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: help-gnu-emacs

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> It definitely felt a little weird writing something like
> "\\w[[:word:]-']+", where we're required to use two different notations
> for the same match.
>

Nothing prevents you from writing

[[:word:]][[:word:]-']+

Robert



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-08  9:16     ` Robert Pluim
@ 2018-06-08  9:24       ` Yuri Khan
  2018-06-08 15:05         ` Eric Abrahamsen
  0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2018-06-08  9:24 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Eric Abrahamsen, help-gnu-emacs

On Fri, Jun 8, 2018 at 4:17 PM Robert Pluim <rpluim@gmail.com> wrote:

> > It definitely felt a little weird writing something like
> > "\\w[[:word:]-']+", where we're required to use two different notations
> > for the same match.
> >
>
> Nothing prevents you from writing
>
> [[:word:]][[:word:]-']+

Or even

(rx wordchar (any wordchar ?- ?'))



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-08  9:24       ` Yuri Khan
@ 2018-06-08 15:05         ` Eric Abrahamsen
  2018-06-09 23:36           ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Abrahamsen @ 2018-06-08 15:05 UTC (permalink / raw)
  To: help-gnu-emacs

Yuri Khan <yurivkhan@gmail.com> writes:

> On Fri, Jun 8, 2018 at 4:17 PM Robert Pluim <rpluim@gmail.com> wrote:
>
>> > It definitely felt a little weird writing something like
>> > "\\w[[:word:]-']+", where we're required to use two different notations
>> > for the same match.
>> >
>>
>> Nothing prevents you from writing
>>
>> [[:word:]][[:word:]-']+
>
> Or even
>
> (rx wordchar (any wordchar ?- ?'))

I know, I know -- there are many ways to skin this cat, and for some
reason I went straight for one that didn't work. Thanks to all for the
other suggestions.

Eric




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-08 15:05         ` Eric Abrahamsen
@ 2018-06-09 23:36           ` Stefan Monnier
  2018-06-10  2:05             ` Eric Abrahamsen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2018-06-09 23:36 UTC (permalink / raw)
  To: help-gnu-emacs

> I know, I know -- there are many ways to skin this cat, and for some
> reason I went straight for one that didn't work. Thanks to all for the
> other suggestions.

If you need help to find other ways that don't work, we'd be happy to
provide many more.


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Difference between \\w and [:word:]?
  2018-06-09 23:36           ` Stefan Monnier
@ 2018-06-10  2:05             ` Eric Abrahamsen
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Abrahamsen @ 2018-06-10  2:05 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I know, I know -- there are many ways to skin this cat, and for some
>> reason I went straight for one that didn't work. Thanks to all for the
>> other suggestions.
>
> If you need help to find other ways that don't work, we'd be happy to
> provide many more.

If I wanted that, I'd post to emacs-tangent, emacs-rabbit-hole, and
emacs-garden-path!




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-06-10  2:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1434.1528399150.1292.help-gnu-emacs@gnu.org>
2018-06-07 23:00 ` Difference between \\w and [:word:]? Ben Bacarisse
2018-06-08  2:29   ` 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

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.