Today I had to write some code to strip both quoted strings and comments from a string. Here are the exact rules: * Strings appear in double quotes (and are terminated one the same line). Any character inside the double quotes preceded by a backslash is "quoted", and in particular the sequences `\"' and `\\' denote a double quote and a backslash in the quoted string. Obviously, this only applies to double quotes outside comments! * Anything from a semicolon (`;') to the end of the line is a comment. Obviously, this only applies to semicolons outside strings! Here's what it looks like in the Perl debugger: DB<> p unquote '1 "\;2) \" 3; " x";" 4' 1 x 4 (the strings are `"\;2) \" 3; "' and `";"') DB<> p unquote '1 ";2) \" 3; "x;" 4' 1 x (there's a string `";2) \" 3; "', and a comment `;" 4') An amazingly readable (to Martians) regexp replacement can do this! Of course, it helps to have read Friedl's _Mastering Regular Expressions_ (and even more to have stolen his string-matching regexp). -- Ariel Scolnicov |"GCAAGAATTGAACTGTAG" |ariels@compugen.co.il Compugen Ltd. |Tel: +972-2-6795059 (Jerusalem) \ NEW IMPROVED URL! 72 Pinhas Rosen St. |Tel: +972-3-7658520 (Main office)`-------------------- Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555 http://3w.compugen.co.il/~ariels ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe