On Wed, Oct 22, 2003 at 07:22:24PM +0200, Kevin Pfeiffer wrote:
In article <[EMAIL PROTECTED]>, Charles K. Clarkson wrote:
Kevin Pfeiffer <[EMAIL PROTECTED]> wrote:
: Where I am stuck is on the question:
: : Given an @array such as
: ("Title of Song", "Artist", "Title", "Another Artist", "etc"),
: is there an easy way to strip out the quotation marks.
s/"//g foreach @array;
Ahhh, that's so nice. I should have known better and just tried that. I'm guessing that in such a format internal quote marks would have to be escaped? So I could do:
s/[^\]"//g... ?
Kevin,
I don't think that's what you want. That will run through your string and, everywhere that it sees a " it will strip the quote and the previous character unless the previous character is a \, in which case it won't do anything. So, yes, it preserves escaped "s, but it accidentally nukes other characters. (Also, you need to escape the \.)
I think what you want is a negative look-behind:
s/(?<!\\)"//g
Note that this will strip a leading quote as well as an internal one. Check http://perldoc.com/perl5.8.0/pod/perlre.html for details on negative (and positive) look-behinds and -aheads. They are very useful.
I was thinking this too, however the assumption was that it was "proper" text in which case the only way a double quote would appear is if it *is* escaped (assuming the prior responses of stripping the leading and trailing double quote) So in this limited case I believe it will work. The look behind would be well suited to text that could have either escape quoted or non-escaped quoted strings, for instance Perl code, etc.
As usual the Mastering Regular Expressions book from ORA has a very good (though somewhat long winded) discussion of this subject, as it is a frequent and important one....
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]