Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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?


Comment on Re: Regex Pipe Return
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010437]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2015-07-31 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls