cmm7825 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex: Matching quoted text
by kennethk (Abbot) on Jun 03, 2010 at 21:04 UTC | |
Re: Regex: Matching quoted text
by JavaFan (Canon) on Jun 03, 2010 at 21:28 UTC | |
by Anonymous Monk on Jun 04, 2010 at 13:38 UTC | |
by Anonymous Monk on Jun 04, 2010 at 14:05 UTC | |
by Anonymous Monk on Jun 04, 2010 at 15:33 UTC | |
by JavaFan (Canon) on Jun 04, 2010 at 15:28 UTC | |
Re: Regex: Matching quoted text
by afoken (Chancellor) on Jun 04, 2010 at 13:54 UTC | |
Re: Regex: Matching quoted text
by choroba (Cardinal) on Jun 03, 2010 at 21:16 UTC | |
by JavaFan (Canon) on Jun 03, 2010 at 21:31 UTC | |
by tye (Sage) on Jun 04, 2010 at 03:46 UTC | |
Re: Regex: Matching quoted text
by Marshall (Canon) on Jun 06, 2010 at 09:42 UTC |