[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: list of regex matches
From: |
Matthew Huggett |
Subject: |
Re: list of regex matches |
Date: |
Mon, 17 Jan 2005 01:23:18 +0900 (JST) |
>> 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.
Thanks very much. This last bit is exactly what I want to do. (But I
didn't know about M-x occur, so I'll be sure to give it a try.)
> Why were you thinking of using a recursive function?
I think I had the wrong idea of how to use 're-search-forward' and was
trying to find a way to step through the buffer.
Thanks again.
Regards,
Matthew Huggett