From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Felix Dietrich Newsgroups: gmane.emacs.help Subject: Re: Negative Lookahead Equivalent in emacs Date: Tue, 09 May 2017 12:03:27 +0200 Organization: solani.org Message-ID: <87vapafits.fsf@sperrhaken.name> References: <49e1dd7d-4be5-4b03-b9e2-e26b15b0a6cb@googlegroups.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1494324334 22514 195.159.176.226 (9 May 2017 10:05:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 9 May 2017 10:05:34 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 09 12:05:31 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d821I-0005dF-Lq for geh-help-gnu-emacs@m.gmane.org; Tue, 09 May 2017 12:05:28 +0200 Original-Received: from localhost ([::1]:36246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d821M-0006O3-JN for geh-help-gnu-emacs@m.gmane.org; Tue, 09 May 2017 06:05:32 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!2.eu.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-X-Trace: solani.org 1494324206 21547 eJwFwQkBwDAIA0BLsPKkciAU/xJ25yc0mBYe5uurAO2QaOBupejWK5HWWv1CXsx9xeEkYewfJ6cSGQ== (9 May 2017 10:03:26 GMT) Original-X-Complaints-To: abuse@news.solani.org Original-NNTP-Posting-Date: Tue, 9 May 2017 10:03:26 +0000 (UTC) Cancel-Lock: sha1:nqHk13WAxG5ZeJicKBKC/lurI5k= sha1:dJo59uPKnbkrcbgGHGFTXBVwYA0= X-User-ID: eJwNydEVADEEBMCWiF2kHOHpv4S7+R2aq3fA6eByJUq5FrEIMy3PxKb9RYP1O3Nl9KiLt8wD8Gou88qhdfEDIu8UPQ== X-NNTP-Posting-Host: eJwNxskBwCAIBMCWdGFByokc/Zdg5jUU25auRlMOB9WVm8Xufycdp/D1RS2QIdd9dThGPG5SHzs/EZ0= Original-Xref: usenet.stanford.edu gnu.emacs.help:219113 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112977 Archived-At: 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