bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27659: 26.0.50; Add string-matched-text: string-match + match-string


From: Philipp Stephani
Subject: bug#27659: 26.0.50; Add string-matched-text: string-match + match-string
Date: Thu, 20 Jul 2017 19:51:22 +0000



Tino Calancha <address@hidden> schrieb am Mi., 12. Juli 2017 um 08:16 Uhr:
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)))

Then,

(let ((str "foo-123"))
  (when (string-match "[[:alpha:]]+-\\([0-9]+\\)" str)
    (match-string 1 str)))
=> "123"

is equivalent to:
(string-matched-text "[[:alpha:]]+-\\([0-9]+\\)" "foo-123" 1)
=> "123"

This looks useful, but I think it would be even better to add it as a pcase macro to be composable (see attached patch). 

Attachment: 0001-Add-rx-pattern-for-pcase.txt
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]