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

As long as you don't have escaped quotes...

Something like "App1 said \"Died -- boom!\" at 3:14am" Would go badly.

Replies are listed 'Best First'.
Re^3: regex match only outside the double quotes
by JavaFan (Canon) on Aug 21, 2009 at 13:27 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.

        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.