all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Felix Dietrich <felix.dietrich@sperrhaken.name>
To: help-gnu-emacs@gnu.org
Subject: Re: Negative Lookahead Equivalent in emacs
Date: Tue, 09 May 2017 12:03:27 +0200	[thread overview]
Message-ID: <87vapafits.fsf@sperrhaken.name> (raw)
In-Reply-To: 49e1dd7d-4be5-4b03-b9e2-e26b15b0a6cb@googlegroups.com

luishenriquezperez@gmail.com writes:

> 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].

For your described behaviour something like the following might come
close to what you had in mind and does not require negative lookahead
support:

    \\(?:[^\n\r\t\f ]*\\([^\n\r\t\f ]\\)\\)\\|^\n

The first shy group "\(?:\)" matches zero or more non-whitespace
characters and one more non-whitespace character (everything following
must be a whitespace character); the one non-whitespace character will
be available as the first group of the resultant match.  Alternatively
"\|" it matches a line beginning with and (depending possibly on the
newline convention) therefore containing only a newline character,
i.e. an empty line.

Don't get confused by the plethora of backslashes: they require escaping
in an Emacs Lisp string to reach the regular expression functions as
proper backslashes; if they were not escaped they themself would escape
the following character.

> But I'm unsure of what the elisp equivalent (if any) of the negative
> lookahead (?!).

I do not know of the existence of an equivalent for the negative
lookahead feature of other regular expression engines in Emacs Lisp
regular expressions.

--
Felix Dietrich


  parent reply	other threads:[~2017-05-09 10:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-09  5:15 Negative Lookahead Equivalent in emacs luishenriquezperez
2017-05-09  7:16 ` Emanuel Berg
2017-05-09  8:44 ` hector
2017-05-09  9:54 ` Wasell
2017-05-10 14:23   ` luishenriquezperez
2017-05-09 10:03 ` Felix Dietrich [this message]
2017-05-09 13:50 ` luishenriquezperez
2017-05-10  1:41   ` Emanuel Berg
2017-05-10 15:51 ` luishenriquezperez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vapafits.fsf@sperrhaken.name \
    --to=felix.dietrich@sperrhaken.name \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.