* pattern-identification-data-extraction-format-string
@ 2015-03-23 0:10 Emanuel Berg
2015-03-23 1:40 ` pattern-identification-data-extraction-format-string Emanuel Berg
0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2015-03-23 0:10 UTC (permalink / raw)
To: help-gnu-emacs
Check this out:
(car
(last
(message-tokenize-header "From: Joe Hacker <get@this.data>"
"<>") )) ; => get@this.data
Is there a more general way to do that, something
along the lines of:
(pattern-identification-data-extraction-format-string
"From: Joe Hacker <get@this.data>"
".*<%1>"
"This is the data I want: %1" )
--
underground experts united
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: pattern-identification-data-extraction-format-string
2015-03-23 0:10 pattern-identification-data-extraction-format-string Emanuel Berg
@ 2015-03-23 1:40 ` Emanuel Berg
2015-03-24 2:32 ` pattern-identification-data-extraction-format-string Emanuel Berg
0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2015-03-23 1:40 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg <embe8573@student.uu.se> writes:
> Check this out:
>
> (car (last (message-tokenize-header "From: Joe
> Hacker <get@this.data>" "<>") )) ; => get@this.data
>
> Is there a more general way to do that, something
> along the lines of:
>
> (pattern-identification-data-extraction-format-string
> "From: Joe Hacker <get@this.data>" ".*<%1>" "This is
> the data I want: %1" )
I was directed to [1], section "Extracting submatches
from a regex match", so I put together
(let ((header "From: Joe Hacker <get@this.data>"))
(save-match-data
(string-match "<\\(.*\\)>" header)
(match-string 1 header) )) ; => "get@this.data"
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.
[1] http://www.emacswiki.org/emacs/ElispCookbook
--
underground experts united
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: pattern-identification-data-extraction-format-string
2015-03-23 1:40 ` pattern-identification-data-extraction-format-string Emanuel Berg
@ 2015-03-24 2:32 ` Emanuel Berg
2015-03-24 8:03 ` pattern-identification-data-extraction-format-string Philipp Stephani
[not found] ` <mailman.2660.1427184219.31049.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-03-24 2:32 UTC (permalink / raw)
To: help-gnu-emacs
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
--
underground experts united
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: pattern-identification-data-extraction-format-string
2015-03-24 2:32 ` pattern-identification-data-extraction-format-string Emanuel Berg
@ 2015-03-24 8:03 ` Philipp Stephani
[not found] ` <mailman.2660.1427184219.31049.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 6+ messages in thread
From: Philipp Stephani @ 2015-03-24 8:03 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
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))))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: pattern-identification-data-extraction-format-string
[not found] ` <mailman.2660.1427184219.31049.help-gnu-emacs@gnu.org>
@ 2015-03-25 0:58 ` Emanuel Berg
2015-03-25 1:03 ` pattern-identification-data-extraction-format-string Emanuel Berg
1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-03-25 0:58 UTC (permalink / raw)
To: help-gnu-emacs
Philipp Stephani <p.stephani2@gmail.com> writes:
> 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))))
I never heard of the 's' package but this
functionality should in some form be included as
a default function! Apart from being useful it is
great PR for Elisp. It would be the first thing I'd
show a C programmer, for example.
--
underground experts united
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: pattern-identification-data-extraction-format-string
[not found] ` <mailman.2660.1427184219.31049.help-gnu-emacs@gnu.org>
2015-03-25 0:58 ` pattern-identification-data-extraction-format-string Emanuel Berg
@ 2015-03-25 1:03 ` Emanuel Berg
1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-03-25 1:03 UTC (permalink / raw)
To: help-gnu-emacs
Philipp Stephani <p.stephani2@gmail.com> writes:
> 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))))
's' is in MELPA as
s is an available package.
Status: Available from melpa -- [Install]
Archive: melpa
Version: 20140910.334
Summary: The long lost Emacs string manipulation library.
Keywords: [strings]
The long lost Emacs string manipulation library.
So "simplify" I don't know. But it looks
interesting nonetheless.
--
underground experts united
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-03-25 1:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-23 0:10 pattern-identification-data-extraction-format-string Emanuel Berg
2015-03-23 1:40 ` pattern-identification-data-extraction-format-string Emanuel Berg
2015-03-24 2:32 ` pattern-identification-data-extraction-format-string Emanuel Berg
2015-03-24 8:03 ` pattern-identification-data-extraction-format-string Philipp Stephani
[not found] ` <mailman.2660.1427184219.31049.help-gnu-emacs@gnu.org>
2015-03-25 0:58 ` pattern-identification-data-extraction-format-string Emanuel Berg
2015-03-25 1:03 ` pattern-identification-data-extraction-format-string Emanuel Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).