Home: Perl Programming Help: Regular Expressions:
values between quotes



ym_chaitu
Novice

Jun 4, 2010, 4:56 AM


Views: 6233
values between quotes

i have a string like this

Quote
<ComposedBlock ID="ZONE1-2" STYLEREFS="PAR1" HEIGHT="1062" WIDTH="1986" HPOS="573" VPOS="3003">




i need to get the values between the " " after the ID= . So how can i do it, Can any one help me??


Bianca
User

Jun 4, 2010, 6:35 AM


Views: 6230
Re: [ym_chaitu] values between quotes

perhaps

Code
#!/usr/bin/env perl 
use strict;
use warnings;
my $string ='<ComposedBlock ID="ZONE1-2" STYLEREFS="PAR1" HEIGHT="1062" WIDTH="1986" HPOS="573" VPOS="3003">';
if ($string =~ /id="([^"]+)"/i) {
print $1;
}



ym_chaitu
Novice

Jun 4, 2010, 7:04 AM


Views: 6227
Re: [Bianca] values between quotes

thank you binaca

i found out the answer..This is the code..

Code
use strict; 
use warnings;

my $string = '<ComposedBlock ID="ZONE1-2" STYLEREFS="PAR1" HEIGHT="1062" WIDTH="1986" HPOS="573" VPOS="3003">';

my ($id) = $string =~ /ID="(.*?)"/;

print $id;

Wink