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 (Priest)
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

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 studying the Monastery: (4)
As of 2016-09-27 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (515 votes). Check out past polls.