in reply to Re^2: regex match only outside the double quotes
in thread regex match only outside the double quotes

  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.
  • Comment on Re^3: regex match only outside the double quotes

Replies are listed 'Best First'.
Re^4: regex match only outside the double quotes
by SuicideJunkie (Vicar) on Aug 21, 2009 at 18:55 UTC
    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.

      Problem is, if you willy-nilly assume the quotes can be escaped, and pick an escape character, you will be completely surprised if the quotes cannot be escaped, or are escaped differently than you expect.

      If things aren't specified, don't assume. Many bugs come from programmer assuming things they shouldn't have.