From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: regex: \(.*\)\([a-zA-Z]+\)$ - not working as expected Date: Wed, 25 Mar 2015 13:57:53 +0100 Message-ID: <20150325125753.GA26005@tuxteam.de> References: <1427286428315-353090.post@n5.nabble.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1427288314 2571 80.91.229.3 (25 Mar 2015 12:58:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Mar 2015 12:58:34 +0000 (UTC) Cc: Help-gnu-emacs@gnu.org To: AngusC Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 25 13:58:29 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Yakt5-0006mo-JA for geh-help-gnu-emacs@m.gmane.org; Wed, 25 Mar 2015 13:58:23 +0100 Original-Received: from localhost ([::1]:38884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yakt4-0006WI-QA for geh-help-gnu-emacs@m.gmane.org; Wed, 25 Mar 2015 08:58:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yaksp-0006W2-JE for Help-gnu-emacs@gnu.org; Wed, 25 Mar 2015 08:58:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yaksj-0003Zl-2r for Help-gnu-emacs@gnu.org; Wed, 25 Mar 2015 08:58:07 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:38873 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yaksi-0003Xg-TE for Help-gnu-emacs@gnu.org; Wed, 25 Mar 2015 08:58:00 -0400 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1Yaksb-0006y4-E5; Wed, 25 Mar 2015 13:57:53 +0100 In-Reply-To: <1427286428315-353090.post@n5.nabble.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:103314 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, Mar 25, 2015 at 05:27:08AM -0700, AngusC wrote: > I have text like this: > > some description here Status1 > some other description Status2 > some other interesting description Status1 (I assume the digits at the end of the lines just don't exist: they disappear later in your post magically anyway ;-) > I am using regex like this: > > \(.*\)\([a-zA-Z]+\)$ I'll try to read the above aloud: "First, try to match zero-or-more of anything, call that \1". "Then try to match at least one character, right before the end-of-line. Call that \2". > with replacement text: > > \1 ZZZ \2 > > And what I expected was: > > some description here ZZZ Status > some other description ZZZ Fault > some other interesting description ZZZ Status Hm. Just why? It seems you expected the *second* match to be "as long as possible", but there's no way you told that: > But instead I got: > > some description here Statu ZZZ s > some other description Faul ZZZ t > some other interesting description Statu ZZZ s Reading aloud the regexp as above makes those matches less mysterious, doesn't it? Now: what could you do? Perhaps you might say that you want the first match to be as short as possible, like so: \(.*?\)\([a-zA-Z]+\)$ > I want my expected outcome, how do I do that? Is that your expected outcome? > What was wrong with my regex? As often (it happens to me all the time!), it's just sloppy specification in your head :-) Regards - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlUSsNEACgkQBcgs9XrR2kbl7ACfXC3spfTmLa7SuVQxf+GXEQSE iQYAnRr2FrWdjn7S4lGP1ZJhEcMV4Tod =JuV3 -----END PGP SIGNATURE-----