For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2007 > Re: How to split a large string with repeating delimiters into multiple









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How to split a large string with repeating delimiters into multiple
Rob Dixon

2007-05-23, 6:59 pm

Michael Goopta wrote:
>
> I am new to Perl.
>
> How can I split the below string and get the multiple
> web-addresses in a list: (i.e. the strings between <upsl-url>
> and </upsl-url>
>
> <upsl-url>http://view-preprod.admission.net/a...;t=ts/r:199x199</upsl-url><upsl-url>http://view-preprod.admission.net/a...:199/h:124&

t=ts/r:199x199</upsl-url>
> </ad-type>
>
> Any help is appreciated.


Hi Michael

The following code will extract all substrings consisting of of 'http:' and all
following characters that aren't '<'. The two URLs appear to be identical in your
example.

Hope this helps,

Rob


use strict;
use warnings;

my $text = '<upsl-url>http://view-preprod.admission.net/a...;t=ts/r:199x199</upsl-url><upsl-url>http://view-preprod.admission.net/a...m:FitPad/w:199/
h:124&t=ts/r:199x199</upsl-url>';

my @urls = $text =~ /http:[^<]+/g;

print "$_\n" foreach @urls;

**OUTPUT**

http://view-preprod.admission.net/a...;t=ts/r:199x199
http://view-preprod.admission.net/a...;t=ts/r:199x199

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com