in reply to regex match only outside the double quotes

You have three cases: This is trivial in a regexp:
s/("[^"]*")|^--.*\n|(--).*/$1||$2||""/egm;

Replies are listed 'Best First'.
Re^2: regex match only outside the double quotes
by SuicideJunkie (Vicar) on Aug 21, 2009 at 13:24 UTC
      1. The OP never said anything about escaped quotes, which I why I didn't include them
      2. I can extend the regexp to include escapes in my sleep, which both hands tied behind my back. And I'd include loop unrolling.
        In many cases the simple way is just fine. In fact I've done the same sort of thing just today; splitting a CSV file on commas because I happen to know that it is safe for my particular input.

        But it is always good to be aware of the potential pitfalls so that you're not completely surprised when the bottom drops out because the input has changed or somebody typed a bad description.