Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Regex Pipe Return

by graff (Chancellor)
on Dec 27, 2012 at 01:41 UTC ( #1010437=note: print w/replies, xml ) Need Help??

in reply to Regex Pipe Return

I'm not sure what you're asking for here:

I want to keep these matches in the context of the larger string, while still being able to distinguish matches. Is there a way to substitute and return the successful event...

If "keep these matches in the context of the larger string" means "don't alter the string", then you wouldn't do a substitution; just do a match (with capturing parens), and assign the return value of the match to an array:

my @strings = qw/XXXXXXXXXABXXXXXXX XXXXXXXBAXXXBBXXXX BBAABAABBXBX/; for my $string ( @strings ) { my @matches = ( $string =~ /([AB]{2})/g ); printf( "Found %d matches in %s: %s\n", scalar @matches, $string, join( ', ', @matches )); }
Perhaps you'd like to mention what you're really trying to accomplish?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010437]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-04-20 10:38 GMT
Find Nodes?
    Voting Booth?