* Substring matched by regex
@ 2008-01-13 4:16 Aaron Maxwell
2008-01-13 9:13 ` Nikos Apostolakis
0 siblings, 1 reply; 4+ messages in thread
From: Aaron Maxwell @ 2008-01-13 4:16 UTC (permalink / raw)
To: help-gnu-emacs
In a function, how do I get the value of a string matched by a regex?
In a function I'm writing, I need to parse the first bit of text matching a
certain regex prior to point. re-search-backward will get the start and end
positions of that string (accessible to me via match-data), but I need a
function that will get the actual text as a string. Something
like "str-from-current-buffer" in this snippet:
(defun fetch-text-to-parse ()
(interactive)
(save-excursion
(progn
(re-search-backward "regexp.to.match")
(str-from-current-buffer (car (match-data)) (cadr (match-data))))))
copy-region-as-kill will kind of work, but it smells like a hack and (more
importantly) pollutes the kill ring. Could someone point me to a good way to
do what I'm trying to do here?
Thanks much.
--
Aaron Maxwell
http://redsymbol.net
Business Owners and Self-Employed: You're NOT Alone!
The Business Butler - http://businessbutler.us
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Substring matched by regex
2008-01-13 4:16 Aaron Maxwell
@ 2008-01-13 9:13 ` Nikos Apostolakis
2008-01-13 17:24 ` Aaron Maxwell
0 siblings, 1 reply; 4+ messages in thread
From: Nikos Apostolakis @ 2008-01-13 9:13 UTC (permalink / raw)
To: help-gnu-emacs
Aaron Maxwell <amax@redsymbol.net> writes:
> In a function, how do I get the value of a string matched by a regex?
>
Is `match-string' what you're looking for?
,----[ C-h f match-string RET ]
| match-string is a compiled Lisp function in `subr.el'.
| (match-string NUM &optional STRING)
|
| Return string of text matched by last search.
| NUM specifies which parenthesized expression in the last regexp.
| Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
| Zero means the entire text matched by the whole regexp or whole string.
| STRING should be given if the last search was by `string-match' on STRING.
|
| [back]
`----
Nikos
> Thanks much.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Substring matched by regex
[not found] <mailman.6094.1200197806.18990.help-gnu-emacs@gnu.org>
@ 2008-01-13 13:58 ` Ralf Angeli
0 siblings, 0 replies; 4+ messages in thread
From: Ralf Angeli @ 2008-01-13 13:58 UTC (permalink / raw)
To: help-gnu-emacs
* Aaron Maxwell (2008-01-13) writes:
> In a function, how do I get the value of a string matched by a regex?
match-string
See (info "(elisp)Simple Match Data").
--
Ralf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Substring matched by regex
2008-01-13 9:13 ` Nikos Apostolakis
@ 2008-01-13 17:24 ` Aaron Maxwell
0 siblings, 0 replies; 4+ messages in thread
From: Aaron Maxwell @ 2008-01-13 17:24 UTC (permalink / raw)
To: help-gnu-emacs
On Sunday 13 January 2008 01:13:54 Nikos Apostolakis wrote:
> Aaron Maxwell <amax@redsymbol.net> writes:
> > In a function, how do I get the value of a string matched by a regex?
> Is `match-string' what you're looking for?
Yes, that's exactly it. Surprised I missed it. Ralf and Nikos, thank you.
--
Aaron Maxwell
http://redsymbol.net
Business Owners and Self-Employed: You're NOT Alone!
The Business Butler - http://businessbutler.us
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-01-13 17:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.6094.1200197806.18990.help-gnu-emacs@gnu.org>
2008-01-13 13:58 ` Substring matched by regex Ralf Angeli
2008-01-13 4:16 Aaron Maxwell
2008-01-13 9:13 ` Nikos Apostolakis
2008-01-13 17:24 ` Aaron Maxwell
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.