I've got huge log files with about 20 fields that I want to split up in to variables using regex. If a field has text it'll be surrounded in quotes like so:

"some data here"

In order to pull the data out of the field I'd use a regex like this: /"([^"]+)/

Which gives me:

some data here

Thats exactly what I want. The problem is if there is no data in that field there is simply a hyphen (-). So I want my regex to either match the double-quotes or the hyphen, when I do this I end up with nested parentheses which throws off my match variables, like this

(("[^"]+)|(-))

I'm not sure if my post made sense, but basically I want to match the data within the quotes, and if there are no quotes, match the hyphen. Either way I want that data to be in the same match variable. Thanks, Chris


In reply to Regex: Matching quoted text by cmm7825

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.