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: Joe Riel
Subject: Re: Match empty string at begin/end of symbol
Date: Wed, 4 Jul 2018 12:37:35 -0700

On Wed, 04 Jul 2018 22:22:15 +0300
Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Wed, 4 Jul 2018 11:43:46 -0700
> > From: Joe Riel <joer@san.rr.com>
> > 
> > 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)))  
> 
> The result of the last form depends on the major mode of the buffer
> where (or in whose minibuffer) you evaluate it.  If it's Lisp or its
> derivatives, it indeed should not match because a Lisp symbol can
> legitimately be named "3+ab", and so "ab" is not at a symbol
> boundary.  But if you try the same in a buffer whose major mode is C
> Mode, you surely get a match, because '+' is not a symbol-constituent
> character in C.
> 
> IOW, I don't think there's a bug here.  It's behaving as intended.
> 

Thanks, Eli.  I verified that by wrapping the call in a with-syntax-table
environment set to the appropriate syntax table; all is well.  


-- 
Joe Riel




reply via email to

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