unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* list of regex matches
@ 2005-01-15 18:32 Matthew Huggett
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Huggett @ 2005-01-15 18:32 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: list of regex matches
       [not found] <mailman.13337.1105815710.27204.help-gnu-emacs@gnu.org>
@ 2005-01-16  9:00 ` Alan Mackenzie
  2005-01-16 16:23   ` Matthew Huggett
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Mackenzie @ 2005-01-16  9:00 UTC (permalink / raw)


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").

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: list of regex matches
  2005-01-16  9:00 ` Alan Mackenzie
@ 2005-01-16 16:23   ` Matthew Huggett
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Huggett @ 2005-01-16 16:23 UTC (permalink / raw)



       >> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-01-16 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-15 18:32 list of regex matches Matthew Huggett
     [not found] <mailman.13337.1105815710.27204.help-gnu-emacs@gnu.org>
2005-01-16  9:00 ` Alan Mackenzie
2005-01-16 16:23   ` Matthew Huggett

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).