* non-greedy regexp
@ 2006-10-23 13:49 Robert Pontisso
2006-10-23 13:52 ` Michaël Cadilhac
0 siblings, 1 reply; 3+ messages in thread
From: Robert Pontisso @ 2006-10-23 13:49 UTC (permalink / raw)
Hi. I've been having difficulty finding a non-greedy
regular expression to match a single instance of an
xml-type tag pair in a line. Given a line with
several instances of <foo>...</foo>, is there a
version of <foo>.*</foo> that won't match everything
between the beginning of the first pair and closing of
the last pair?
Thanks
Send instant messages to your online friends http://uk.messenger.yahoo.com
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <mailman.154.1161611374.27805.help-gnu-emacs@gnu.org>]
* Re: non-greedy regexp
[not found] <mailman.154.1161611374.27805.help-gnu-emacs@gnu.org>
@ 2006-10-23 13:57 ` David Kastrup
0 siblings, 0 replies; 3+ messages in thread
From: David Kastrup @ 2006-10-23 13:57 UTC (permalink / raw)
Robert Pontisso <rpontisso@yahoo.co.uk> writes:
> Hi. I've been having difficulty finding a non-greedy
> regular expression to match a single instance of an
> xml-type tag pair in a line. Given a line with
> several instances of <foo>...</foo>, is there a
> version of <foo>.*</foo> that won't match everything
> between the beginning of the first pair and closing of
> the last pair?
Well, <foo>.*?</foo> would be one possibility, but that does not cover
nested tags. You'd probably want something like
(let ((level 0))
(while (progn
(search-forward-regexp "<\\(/\\)?foo>")
(setq level (if (match-beginning 1) (1- level) (1+ level)))
(> 0 level))))
in order to match nested tags.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-10-23 13:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-23 13:49 non-greedy regexp Robert Pontisso
2006-10-23 13:52 ` Michaël Cadilhac
[not found] <mailman.154.1161611374.27805.help-gnu-emacs@gnu.org>
2006-10-23 13:57 ` David Kastrup
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).