Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by BillKSmith (Chaplain)
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 drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-08-02 06:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls