Gossamer Forum
Home : General : Perl Programming :

another regex question

Quote Reply
another regex question
i am reading a file and found a line i want that is stored in $line:

$db_name = "Bidders - Private";

i want to get rid of everything except what's inside the quotes: Bidders - Private. that is i want to remove $db_name = " and the "; at end of line. i can't figure out how to do it!

thanks
Quote Reply
Re: [delicia] another regex question In reply to
Hi,

Without knowing much more, this should do the trick:

Code:
my @loop = split /\n/, q|
some line
$db_name = "Bidders - Private";
more values|;

my $db_value;
foreach (@loop) {
m/\$db_name = "(.+?)"/ and $db_value = $1;
}
print "GOT: $db_value \n";

Tested that locally, and all looks good Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Post deleted by delicia In reply to
Quote Reply
Re: [Andy] another regex question In reply to
i figured out a way to get what i wanted:

($dispname1,$dispname2,$dispname3) = split (/\"/, $dispname);

$dispname2 is the part i want!

sorry but i couldn't understand what you gave me but i'm sure it was more elegant than mine! thanks!
Quote Reply
Re: [delicia] another regex question In reply to
This is probably what you want instead Smile

Code:
if ($line =~ /^\$db_name/ ) { $line =~ m/\$db_name = "(.+?)"/ and $dispname = $1; }

$dispname would then hold the value between the " and "

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] another regex question In reply to
perfect. thanks!

Last edited by:

delicia: Feb 14, 2012, 2:50 PM