Leave a Reply

6 comments

  1. Thanks, you saved me some time writing my own expression

    Michael Beantwoorden

  2. You saved me from writting my own expression, too.
    Thanks a lot!

    Franz Beantwoorden

  3. this slight modification will remove the quotes from the returned values:

    “?;”?(?=(?:[^”]*”[^”]*”)*(?![^”]*”))”?

    thanks!! =)

    andy Beantwoorden

  4. Woah, thanks.

    Pretty cool.

    monk.e.boy Beantwoorden

  5. When I tried the expressions above, they were capturing the ; rather than the fields.

    The expression below handles ; or , and returns the individual cells as named groups:

    (((?:”)(?[^”]+)(?:”))|((?[^,;”]+)(?!”)))(?:[,;])?

    (?:”)(?[^”]+)(?:”) captures any quoted cells while

    (?[^,;”]+)(?!”) captures any unquoted cells.

    Note the use of (?

    Adrian J Beantwoorden

  6. After further testing I made some modifications to the expression. The prior expresion did not handle empty fields.

    This expression is more effective:

    (?<=^|[,;])(((?:")(?[^”]*)(?:”))|((?[^,;”]*)(?!”)))(?=[,;]|$)
    (?<=^|[,;]) ensures the field is preceeded by the start of the line or , or ; (?=[,;]|$) ensures the field is follwoed by the end of line or , or ; The field capture was cahnged to use * rather than + to capture empty fields

    Adrian J Beantwoorden