On Dec 12, 2005, at 04:40, $Bill Luebkert wrote:
DZ-Jay wrote:
But I did specify the rules:
1. Split on a specified delimiter (for the moment I'm aiming for [,;]),
but ideally I would like it to be variable.
2. As opposed to CSV where quoted strings encompass the entire field,
quoted substrings can exist within the field.
3. The quotes surrounding a substring are part of the field and should
not be removed.
4. Escaped quotes (\") can exist within quoted substrings.
Once or more than once ?
More than once, as the example shows.
5. The delimiter can exist within the quoted substrings.
One or more ? More than one can complicate.
More than once. Its not as complicated as you may think; the first match in my
regexp catches those by accepting absolutely *anything* within quotation marks
(not even looking for delimiters there).
And this is an example that covers all the rules:
$foo = qq!"LastName, FirstName" <address>, "Name" <address> ,
<address>; FirstName LastName , address; "First \"nick\" Last"
address!;
Are the <>'s literal or do they indicate a generic address and what
characters can exist in the name and address besides \w chars ?
The <>'s are literal and can contain any characters within it. As I mentioned
in my first e-mail, I want this to be generic and to adhere to the rules I
mentioned, without any expectations on what characters to find in any
particular place.
Making a single RE to handle this would take to much effort when you
have a simpler solution and since it's time consuming, I'll pass for
now (plus I'm no expert at REs - I'm self taught).
I agree, and I am also self-taught and certainly not an expert at regexps. I
would like to get a single regexp, if possible, as a matter of challenge and
learning. As I mentioned in my first post, the regexp I came up with, after
modifying the CSV-split example in the Perl Cookbook, worked beautifully -- all
except for trailing whitespace of a field (spaces before the delimiter). It
would have been even easier for me to just $_ =~ /\s*$//; each field at the
end, but I want to learn what I missed, and perhaps improve my work.
Thanks for all your help!
dZ.
--
Trying to teach good programming habits in VB6 is like trying to teach proper
hygiene in a sewer.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs