all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* regex nirvana - near miss
@ 2014-06-26 15:18 Buchs, Kevin J.
  2014-06-26 15:36 ` Yuri Khan
  2014-06-26 16:35 ` Drew Adams
  0 siblings, 2 replies; 4+ messages in thread
From: Buchs, Kevin J. @ 2014-06-26 15:18 UTC (permalink / raw)
  To: help-gnu-emacs

Often I wish to match a string not followed by another string, e.g. 
"abc" without "def" following. I had a glimpse of nirvana today when I 
thought of trying this RE:  abc\(def\)\{0\}, but alas it was not to be 
had as it gets optimized and just matches "abc". It is tedious to use:  
abc\([^d]\|d[^e]\|de[^f]\), especially when the second string gets longer.

-- 
Kevin Buchs   Research Computer Services   Phone: 507-538-5459
Mayo Clinic   200 1st. St SW   Rochester, MN 55905
http://mayoclinic.org  http://facebook.com/MayoClinic  http://youtube.com/MayoClinic  http://twitter.com/MayoClinic




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

* Re: regex nirvana - near miss
  2014-06-26 15:18 regex nirvana - near miss Buchs, Kevin J.
@ 2014-06-26 15:36 ` Yuri Khan
  2014-06-26 16:35 ` Drew Adams
  1 sibling, 0 replies; 4+ messages in thread
From: Yuri Khan @ 2014-06-26 15:36 UTC (permalink / raw)
  To: Buchs, Kevin J.; +Cc: help-gnu-emacs@gnu.org

On Thu, Jun 26, 2014 at 10:18 PM, Buchs, Kevin J. <buchs.kevin@mayo.edu> wrote:

> Often I wish to match a string not followed by another string, e.g. "abc"
> without "def" following. I had a glimpse of nirvana today when I thought of
> trying this RE:  abc\(def\)\{0\}, but alas it was not to be had as it gets
> optimized and just matches "abc". It is tedious to use:
> abc\([^d]\|d[^e]\|de[^f]\), especially when the second string gets longer.

What you are looking for is called a negative lookahead assertion, and
no, Emacs currently does not support them.



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

* Re: regex nirvana - near miss
       [not found] <mailman.4351.1403795929.1147.help-gnu-emacs@gnu.org>
@ 2014-06-26 15:38 ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-06-26 15:38 UTC (permalink / raw)
  To: help-gnu-emacs

> Often I wish to match a string not followed by another string, e.g. "abc"
> without "def" following.

Indeed, negation is sorely lacking from Emacs's regexps.

BTW, the notion of negation in regexps is not quite as simple as it
sounds.  E.g. regexps supported by lex.el (in GNU ELPA) do include
a negation operator, but not the one you want: (seq "abc" (not "def"))
will happily match "abcdefg" (stopping at "abc", "abcd", "abcde", or
"abcdefg").


        Stefan


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

* RE: regex nirvana - near miss
  2014-06-26 15:18 regex nirvana - near miss Buchs, Kevin J.
  2014-06-26 15:36 ` Yuri Khan
@ 2014-06-26 16:35 ` Drew Adams
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2014-06-26 16:35 UTC (permalink / raw)
  To: Buchs, Kevin J., help-gnu-emacs

> Often I wish to match a string not followed by another string, e.g.
> "abc" without "def" following.

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.

For example, you want to find a match for `abc' that does not also
match `def' at the `abc' match end.  Search for `abc', and then
programmatically exclude search hits where `def' follows `abc'.

Or if you want to complement a set of regexp matches, compute it
and then subtract it from the original search space.



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

end of thread, other threads:[~2014-06-26 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-26 15:18 regex nirvana - near miss Buchs, Kevin J.
2014-06-26 15:36 ` Yuri Khan
2014-06-26 16:35 ` Drew Adams
     [not found] <mailman.4351.1403795929.1147.help-gnu-emacs@gnu.org>
2014-06-26 15:38 ` Stefan Monnier

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.