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: Tino Calancha
Subject: bug#27659: 26.0.50; Add string-matched-text: string-match + match-string
Date: Fri, 21 Jul 2017 21:29:08 +0900 (JST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)



On Thu, 20 Jul 2017, Philipp Stephani wrote:



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). 
Thank you!
Although, i must admit i am not fluent in `rx' syntaxis, i find your idea
very nice.

Tino

reply via email to

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