Your post would be clearer if you used <code>...</code> tags around your code and data. (You can still go back and add those I think.)

I'm guessing at the real format of your input data, since I think you might have two lines run together. The following might do what you want:

#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my @lines = <DATA>; check3($_) foreach @lines; sub check3 { my ($str) = @_; if ($str =~ m{ ^ # Beginning of line \s* # optional space constant # "constant" \s+ # required space (fixup|/\*fixup\*/|) # "fixup" or "/*fixup*/" or "" (captur +ed) \s* # optional space (private|) # "private" or "" (captured) \s* # optional space (\w+) # type/typedef name (captured) \s* # optional space = # "=" \s* # optional space (?: # grouping 1 start (?: # grouping 1.1 start (U1 format) < # "<" start of U1 format ([[:alnum:]]+) # part a" of U1 format (captur +ed) \s+ # required space ([[:alnum:]]+) # part b of U1 format (captur +ed) > # ">" end of U1 format ) # grouping 1.1 end | # or groupings 1.1 & 1.2 (?: # grouping 1.2 start (filename for +mat) " # Filename start quote ([[:alnum:]_/\\\.:]+) # Filename (captured) " # Filename end quote ) # grouping 1.2 end ) # grouping 1 end \s* # optional space (?: # grouping 2 start /\*\s*(.*?)\s*\*/ # "comment" or undef (captured +) | # or # blank ) # grouping 2 end }x ) { print "3: MATCH\n"; my ($fixup,$private,$name,$u1a,$u1b,$filename,$comment) = ($1, +$2,$3,$4,$5,$6,$7); print "fixup=\"$fixup\" "; print "private=\"$private\" "; print "name=\"$name\" "; print "u1a=\"".(defined $u1a ? $u1a : "undef")."\" "; print "u1b=\"".(defined $u1b ? $u1b : "undef")."\" "; print "filename=\"".(defined $filename ? $filename : "undef"). +"\" "; print "comment=\"".(defined $comment ? $comment : "undef")."\" + "; print "\n"; } else { print "3: Sorry Charlie\n"; } } __DATA__ constant fixup private AlarmFileName = "C:\TMP\ALARM.LOG" constant fixup ConfigAlarms = <U1 0> /* U1 Format */

Here's the output I get:

3: MATCH fixup="fixup" private="private" name="AlarmFileName" u1a="undef" u1b=" +undef" filename="C:\TMP\ALARM.LOG" comment="undef" 3: MATCH fixup="fixup" private="" name="ConfigAlarms" u1a="U1" u1b="0" filename +="undef" comment="U1 Format"

In reply to Re: How to parsing quoted strings in my case. by gmargo
in thread How to parsing quoted strings in my case. by Anonymous Monk

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.