[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: list of regex matches
From: |
Alan Mackenzie |
Subject: |
Re: list of regex matches |
Date: |
Sun, 16 Jan 2005 09:00:23 +0000 |
User-agent: |
tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686)) |
Matthew Huggett <mhuggett@zam.att.ne.jp> wrote on Sun, 16 Jan 2005
03:32:30 +0900 (JST):
> Hi,
> I'd like to build a list of regular expression matches. Specifically,
> I have a buffer in which some text is surrounded by || characters. I'd
> like to build a list of all these chunks of || <some text> ||. I
> thought that maybe I could use a recursive function that makes calls to
> (re-search-forward...) but I haven't got it right yet. Any suggestions
> would be appreciated. I'm looking for a function that would take a
> buffer or even a string and return a list of strings that matched a
> regular expression.
If by "building a list" you mean you want to look at that list rather
than using it in a program, M-x occur is exactly the function you're
looking for. M-x occur is also a handy way of debugging a regexp which
you need in a lisp function.
If you want to process that list, then `re-search-forward' is indeed the
thing. After a successful `re-search-forward', the three functions
`buffer-substring', `match-beginning' and `match-end' will enable you to
copy the string out of the buffer. You can then cons all these strings
together as you find them.
Why were you thinking of using a recursive function?
--
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").