Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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 about the Monastery: (5)
As of 2018-06-22 11:43 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.