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

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

Re: Negative Lookahead Equivalent in emacs


From: hector
Subject: Re: Negative Lookahead Equivalent in emacs
Date: Tue, 9 May 2017 10:44:28 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

On Mon, May 08, 2017 at 10:15:42PM -0700, luishenriquezperez@gmail.com wrote:
> Hi,
> 
> I'm trying to write a regex that matches the last character of a sequence of 
> non-whitespace characters '[^\n\r\t\f ]', or an empty line matching ^$. 
> 
> Thus: 
> Hello World! --> "o" and "!" would be matched
> 
> In non-elisp regex languages I know the code for this is: \S(?!\S) 
> I know that \S is equivalent too [^ /n/r/t/f]. 
> But I'm unsure of what the elisp equivalent (if any) of the negative 
> lookahead (?!).
> 
> I saw on this forum a post  "gnu.emacs.help › regex nirvana - near miss"
> Where Drew Adams said: "Typically, what you want to do for this in Emacs Lisp 
> is to combine 
> the use of a regexp for positive matching with other code that takes 
> care of the non-matching (negation) need. "
> 
> However, I'm not sure how to go about doing this.

Perhaps

\\S-\\s-

or

[^[:space:]][[:space:]]

not including the ^$. I guess you just had to add "\\|^$" to the preceding 
expressions.
I'm not sure if there is any difference between the two syntaxes.

Note that these expressions depend on the syntax table. So the definition of
"[[:space:]]" can change depending on syntax table. It is not necessarily
"[\n\t\f\r\v ]"



reply via email to

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