Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Curios use of regular expressions in split

by Riales (Hermit)
on Feb 15, 2012 at 17:39 UTC ( #954012=note: print w/ replies, xml ) Need Help??


in reply to Curios use of regular expressions in split

I don't know if anybody has a better solution, but you could just take two steps to both capture what you want to capture and split the string:

my $string = "uno abc dos"; my @a = split /abc/, $string; $string =~ /(abc)/; ...some use of $1...

If your pattern is just something as trivial as abc, you could just assume $1 = 'abc'...but I'm assuming it's not.


Comment on Re: Curios use of regular expressions in split
Select or Download Code
Re^2: Curios use of regular expressions in split
by Anonymous Monk on Feb 15, 2012 at 17:45 UTC
    my @matches = $input =~ /$re/g; my @splits = split /$re/, $input;
Re^2: Curios use of regular expressions in split
by juliosergio (Acolyte) on Feb 15, 2012 at 18:55 UTC

    Up to now, I think yours is the best solution, though, I was trying to do it in a single step..
    Thanks!,
    -Sergio

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2015-07-06 15:17 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 (77 votes), past polls