From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#27659: 26.0.50; Add string-matched-text: string-match + match-string Date: Wed, 12 Jul 2017 15:13:42 +0900 Message-ID: <87fue2rxm1.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1499840180 30612 195.159.176.226 (12 Jul 2017 06:16:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 12 Jul 2017 06:16:20 +0000 (UTC) To: 27659@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 12 08:16:15 2017 Return-path: Envelope-to: geb-bug-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 1dVAwY-0007Pp-2f for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Jul 2017 08:16:14 +0200 Original-Received: from localhost ([::1]:50587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAwY-0001vC-4e for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Jul 2017 02:16:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAwQ-0001v5-JT for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2017 02:16:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAwM-0005gk-Fe for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2017 02:16:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60188) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVAwM-0005gg-Bj for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2017 02:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dVAwM-000357-64 for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2017 02:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Jul 2017 06:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27659 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.149984010411770 (code B ref -1); Wed, 12 Jul 2017 06:16:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Jul 2017 06:15:04 +0000 Original-Received: from localhost ([127.0.0.1]:34632 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVAvQ-00033m-Fq for submit@debbugs.gnu.org; Wed, 12 Jul 2017 02:15:04 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34086) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVAvO-00032y-Rb for submit@debbugs.gnu.org; Wed, 12 Jul 2017 02:15:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAvI-0005Cs-MV for submit@debbugs.gnu.org; Wed, 12 Jul 2017 02:14:57 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:60845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVAvI-0005Cm-Ic for submit@debbugs.gnu.org; Wed, 12 Jul 2017 02:14:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVAvH-0001ml-AD for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2017 02:14:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVAvE-0005Bk-4T for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2017 02:14:55 -0400 Original-Received: from mail-pf0-f193.google.com ([209.85.192.193]:34306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVAvD-0005BE-T6 for bug-gnu-emacs@gnu.org; Wed, 12 Jul 2017 02:14:52 -0400 Original-Received: by mail-pf0-f193.google.com with SMTP id c24so1926508pfe.1 for ; Tue, 11 Jul 2017 23:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/8UtFjbSjsE2o+MddT/8wEr2MxMWD5sMcXuWs0GklA0=; b=Ago1X5jg1T/5zIM5/1d4HcmHuGV3c4K3JpUmcPeKPJ6bAxTkOgzuV54XnqBUcsrHcM pQ0S8TXLo8p84w0mjrrxrpuN/uidAILo0Lj7/y0m9E6N1HY+zmGpAg8nO/uSEMzOWOJj avCfwLV/9++sGVCP+tn9uoH8egxGJEGhrdCjA6rLpevXGZhDQcOhKngV9PRlrjHVvHiW ytCWdlfiyRn8XIusUDY9vQkMoFH8n7k70eKwZBt3cFz2u/0n8Vl1sTatwv8mJ+72lj9e b+kpCdntF/Wre3MEivZ1BqR+IHdwx3NiHHElojfJOBqpkIPw4c8WnudrNOzpBXaCPoJX q4zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/8UtFjbSjsE2o+MddT/8wEr2MxMWD5sMcXuWs0GklA0=; b=RW5eDDUJFHHYkG9bpUexKOVeosf2sKmQb2gEtvNX1nVHqAqXPUFEjCIwK8kqVHyym0 oSNIdsrAUjZedDlUHrFlc69oXDZ4Armt/K+dZjN/NBnRjdJWD1JGQ3VUXfiNWQ/1qR/7 1/TJKK0OkgZfqtHpTdRdZLIZwLShjD3cahOAObPpicMQ65t3APELArzdWGynvde2JyMX INzGiWlxHB6UAx5oWxKKZsWp5Ensz3vrWaHUGNPIZ1RmBKzJgg6YxMsSr+GWACDj4qPD WCoaXl4TJkn8EZoNK6Rgrgcjy0X8P3X6nAxVbCxfxTs5+PLfOZvtsBOD05MWOmqXe9H+ 03LA== X-Gm-Message-State: AIVw112uk8cnv6v2woH9w9rhgwum75sEwJOyvUjqruiQ0oRMQN3H6Le/ J7ghczVt95t3WISB X-Received: by 10.98.204.194 with SMTP id j63mr53594532pfk.137.1499840029130; Tue, 11 Jul 2017 23:13:49 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id r17sm2380377pfk.73.2017.07.11.23.13.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2017 23:13:48 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134450 Archived-At: Severity: wishlist Just wondering if the following is of any interest: (defun string-matched-text (regexp string num &optional start) "" (when (string-match regexp string start) (match-string num string))) =20=20=20=20 Then, (let ((str "foo-123")) (when (string-match "[[:alpha:]]+-\\([0-9]+\\)" str) (match-string 1 str))) =3D> "123" is equivalent to: (string-matched-text "[[:alpha:]]+-\\([0-9]+\\)" "foo-123" 1) =3D> "123" --8<-----------------------------cut here---------------start------------->= 8--- commit 65741b74d8999beaacd5093e128030a8635aff05 Author: Tino Calancha Date: Wed Jul 12 14:29:08 2017 +0900 string-matched-text: New function =20=20=20=20 * lisp/subr.el (string-matched-text): New defun. * doc/lispref/searching.texi (Simple Match Data): Update manual. * etc/NEWS: Announce it. diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index 67d4c22464..81bcad1740 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi @@ -1457,6 +1457,16 @@ Simple Match Data repetition that repeated zero times. @end defun =20 +@defun string-matched-text regexp string count &optional start +This function returns, as a string, the text matched by @var{regexp} +in @var{string}, or @code{nil} if there is no match. The meaning +of @var{count} is same as in @code{match-string}. If @var{start} +is non-@code{nil}, the search starts at that index in @var{string}. +The behavior of this function is equivalent to +@w{@code{(and (string-match @var{regexp} @var{string} @var{start}) +(match-string @var{count} @var{string}))}}. +@end defun + @defun match-string-no-properties count &optional in-string This function is like @code{match-string} except that the result has no text properties. diff --git a/etc/NEWS b/etc/NEWS index 68ebdb3c15..794edef9cd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1105,6 +1105,8 @@ break. * Lisp Changes in Emacs 26.1 =20 +** New function 'string-matched-text'. + ** New function 'seq-set-equal-p' to check if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of the order. =20 diff --git a/lisp/subr.el b/lisp/subr.el index a9edff6166..1482787842 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3635,6 +3635,15 @@ match-string (substring string (match-beginning num) (match-end num)) (buffer-substring (match-beginning num) (match-end num))))) =20 +(defun string-matched-text (regexp string num &optional start) + "Return string of text matched by REGEXP in STRING. +NUM specifies which parenthesized expression in REGEXP. + Value is nil if NUMth pair didn=E2=80=99t match, or there were less than= NUM pairs. +Zero means the entire text matched by the whole regexp or whole string. +If optional arg START is non-nil, then start search at that index in STRIN= G." + (when (string-match regexp string start) + (match-string num string))) + (defun match-string-no-properties (num &optional string) "Return string of text matched by last search, without text properties. NUM specifies which parenthesized expression in the last regexp. --8<-----------------------------cut here---------------end--------------->= 8--- In GNU Emacs 26.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-07-11 Repository revision: d014a5e15c1110af77e7a96f06ccd0f0cafb099f