* 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
* Re: non-greedy regexp
2006-10-23 13:49 Robert Pontisso
@ 2006-10-23 13:52 ` Michaël Cadilhac
0 siblings, 0 replies; 3+ messages in thread
From: Michaël Cadilhac @ 2006-10-23 13:52 UTC (permalink / raw)
Cc: help-gnu-emacs
[-- Attachment #1.1: Type: text/plain, Size: 843 bytes --]
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?
Is «<foo>.*?</foo>» what you're looking for?
--
/!\ My mail address changed, please update your files accordingly.
| Michaël `Micha' Cadilhac | Si les religions etaient aussi tole- |
| Epita/LRDE Promo 2007 | rantes qu'elles le pretendent, il y |
| http://michael.cadilhac.name | a longtemps qu'il n'y en aurait plus |
`-- - JID: micha@amessage.be --' -- Moustic - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 3+ messages in thread
* 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 --
[not found] <mailman.154.1161611374.27805.help-gnu-emacs@gnu.org>
2006-10-23 13:57 ` non-greedy regexp David Kastrup
2006-10-23 13:49 Robert Pontisso
2006-10-23 13:52 ` Michaël Cadilhac
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.