Re: Extract until unquote or EOL
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Mon, 18 Jul 2005 18:43:38 GMT
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
.
- Follow-Ups:
- Re: Extract until unquote or EOL
- From: Mats
- Re: Extract until unquote or EOL
- From: Gunnar Hjalmarsson
- Re: Extract until unquote or EOL
- References:
- Extract until unquote or EOL
- From: Mats
- Extract until unquote or EOL
- Prev by Date: Re: Lower casing letters of words
- Next by Date: Re: Extract until unquote or EOL
- Previous by thread: Extract until unquote or EOL
- Next by thread: Re: Extract until unquote or EOL
- Index(es):
Relevant Pages
|