help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Match empty string at begin/end of symbol


From: Teemu Likonen
Subject: Re: Match empty string at begin/end of symbol
Date: Wed, 04 Jul 2018 22:25:10 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux)

Joe Riel [2018-07-04 11:43:46-07] wrote:

> The regular expressions '\_<' and '\_>'
> seem to be broken in Emacs 25.1.1.  Consider
>
> (let ((str "3+ab"))
>   (and (string-match "\\<[a-zA-Z][a-zA-Z0-9]*" str)
>        (match-string 0 str)))
>  
> That returns "ab", as expected.  Change the "\\<" to "\\_<"
> and it no longer matches.  Why not?
>
> (let ((str "3+ab"))
>   (and (string-match "\\_<[a-zA-Z][a-zA-Z0-9]*" str)
>        (match-string 0 str)))

Because "+" is a symbol character too. See this:


    ELISP> (let ((str "3+ab"))
             (and (string-match "\\_<.+\\_>" str)
                  (match-string 0 str)))

    "3+ab"



-- 
/// Teemu Likonen   - .-..   <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]