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

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

Re: pattern-identification-data-extraction-format-string


From: Philipp Stephani
Subject: Re: pattern-identification-data-extraction-format-string
Date: Tue, 24 Mar 2015 08:03:34 +0000

Emanuel Berg <embe8573@student.uu.se> schrieb am Di., 24. März 2015 um
03:30 Uhr:

> Emanuel Berg <embe8573@student.uu.se> writes:
>
> > ... section "Extracting submatches from a regex
> > match", so I put together ...
> >
> > Maybe my original solution to that particular
> > problem is just as good, but I asked for a generic
> > way and this seems to be it.
>
> Even cooler:
>
>     (defun make-match-list (num string)
>       (let ((match (match-string num string)))
>         (if match (cons match (make-match-list (1+ num) string) ))))
>
>     (defun match-data-format (data match format-str)
>       (save-match-data
>         (string-match match data)
>         (eval `(message format-str ,@(make-match-list 1 data) ))))
>
>     (match-data-format
>      "From: Joe Hacker <get@this.data>"
>      "\\(.*\\): *\\(.*[[:alnum:]]\\) *<\\(.*\\)>"
>      "header is: %s\nname is: %s\ne-mail is: %s") ; eval me
>
>
Using the 's' package you could simplify this to:

(require 's)
(defun match-data-format (data match format-str)
  (apply #'message format-str (cdr (s-match match data))))


reply via email to

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