in reply to Perl Problems with Matching Expression Patterns

At the begining of each second item, you're looking for an optional quote, an optional (, and then an optional space. But since the space comes first, the quote goes into your $2. Secondly, [\S\s] matches everything, so it's equivalent to ., so it's consuming everything to the end of the line (it's greedy), and leaving nothing for your trailing modifiers. I think if I had it to write, here's how I would do it.
use strict; use warnings; while (<DATA>) { if (/^\s*(\w+)[\s:"(]+(.+?)[\s");]*$/) { print "FIRST TERM - $1\n"; print "SECON TERM - $2\n"; } } __DATA__ date : "April 27, 2004"; comment : "Copyright (c) 2002 FoodNation Technolo, Inc. "; power_watts : "1pC"; fruits_vegs_food (1.0, pound);
that is, you start with optional whitespace, then your first term, then some delimiter, then the rest.

Replies are listed 'Best First'.
Re^2: Perl Problems with Matching Expression Patterns
by EchoAngel (Pilgrim) on Jan 12, 2005 at 21:17 UTC
    wow, your right , \S is eatting everything, thanks