Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Capturing substrings with complex delimiter, up to a maximum

by BillKSmith (Deacon)
on Oct 30, 2013 at 03:46 UTC ( #1060262=note: print w/ replies, xml ) Need Help??


in reply to Capturing substrings with complex delimiter, up to a maximum

Remember that split takes a regex as it first argument. Use a lookahead assertion after the comma.

use strict; use warnings; use Data::Dumper; my $input = q|http://abc.org,http://de,f.org,https://ghi.org,http://jk +l.org|; my @urls = (split /,(?=http)/, $input, 4)[0..2]; print Dumper \@urls;
Output:
$VAR1 = [ 'http://abc.org', 'http://de,f.org', 'https://ghi.org' ];
Bill


Comment on Re: Capturing substrings with complex delimiter, up to a maximum
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2015-07-01 19:25 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 (17 votes), past polls