Re: Extract until unquote or EOL
- From: Mats <spamenot.mog.pettersson@xxxxxxxxx>
- Date: Mon, 18 Jul 2005 19:09:57 GMT
John W. Krahn wrote:
Mats wrote:
I've messed with this problem a while now. I want to parse a file for declarations (ex: NAME = "myname").
I wan't to extract the phrase/text between the two quotes. BUT If the last quote isn't available (type/user error) then it should extract until end of line. If no quotes are there at all, it should extract the whole line (except NAME=). If there are several double quotes, it should extract between the first two (that i seem to have achived).
My current testscript looks as below:
--- #!/usr/bin/perl -w
use strict;
$_ = 'NAME = "between quotes" not this" nor this';
print $1."\n" if m/\s*NAME\s*=\s*"*(.*?)"|$/s; ---
This prints out as i want: between quotes
But if i delete the last two doublequotes and just keep the first it prints nothing. If i delete the first doublequote also, i get an "uninitialized value" error.
Anybody knows a smooth solution to this?
print "$1\n" if /\s*NAME\s*=\s*"?([^"]+)/;
John
Well! Thats a lot less complicated and smarter than i ever thought off and as bonus it works! I really should be thinking in a more KISS like way.
Thanks!
Mats .
- References:
- Extract until unquote or EOL
- From: Mats
- Re: Extract until unquote or EOL
- From: John W. Krahn
- Extract until unquote or EOL
- Prev by Date: Re: PAR 0.89 + Socket + ASP 5.8.7 = PL_memory_wrap
- Next by Date: Re: Lower casing letters of words
- Previous by thread: Re: Extract until unquote or EOL
- Next by thread: Re: Extract until unquote or EOL
- Index(es):
Relevant Pages
|