Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 meditating upon the Monastery: (9)
As of 2014-12-22 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls