Extract until unquote or EOL



Hi!

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?

Mats
.



Relevant Pages

  • Re: problem with spaces in quoted string arguments
    ... Janis Papanagnou wrote: ... are in double quotes. ... As can be seen in the output, the server called "photon hub" did not ... extract properly, since the space was detected in the argument to awk. ...
    (comp.unix.shell)
  • Re: Problem with Importing CSV with "=" inside a field value
    ... is a small Access database ... and have overcome a number of obstacles. ... it has an equal sign at the front and wrapped by quotes. ... Any way to skip parsing this field such that Access can extract the fields ...
    (microsoft.public.access.externaldata)
  • Re: python fast HTML data extraction library
    ... any quotes at all. ... (just realized that condition check REs need an update too:/). ... extract the data entries from the table at this URL:http://tf.nist.gov/tf-cgi/servers.cgi? ... Thanks for pointing this out, ...
    (comp.lang.python)
  • Re: Extract until unquote or EOL
    ... > I wan't to extract the phrase/text between the two quotes. ... > last quote isn't available (type/user error) then it should extract ... If i delete the first doublequote also, ...
    (comp.lang.perl.misc)
  • Re: Problem with Importing CSV with "=" inside a field value
    ... and have overcome a number of obstacles. ... it has an equal sign at the front and wrapped by quotes. ... This problematic field actually is of no use to me. ... Any way to skip parsing this field such that Access can extract the fields ...
    (microsoft.public.access.externaldata)