develooper Front page | perl.beginners | Postings from March 2002

Vexing regex question--storing multiple hits for later use

Thread Next
From:
Daniel J. Tomso
Date:
March 6, 2002 00:46
Subject:
Vexing regex question--storing multiple hits for later use
Message ID:
1015370896.7501.6.camel@greenbriar.niehs.nih.gov
Greetings.

I'm matching a pattern against a long string, and I want to examine each
occurrence of the match.  I know that $& stores the match, but is there
a way to store EVERY match in the string, and then look at them?

Example:

$str = "This is a very long string, isn't it?"

If I want to match against something like /i[st]/ to pick up all the
'is' and 'it' strings, then see what I've got (i.e. each instance), can
I do it?

I've tried to wade through the whole \G /g etc. world, but it doesn't
seem to work for me.

Thanks!

Dan T.
planted@nc.rr.com


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About