Frage

I am attempting to pull apart a row from a CSV file without using a parser and all I need to do is split the string based on the commas using php. In itself this is fairly easy if you have no commas in the input, which isn't the case. I want to ignore the commas that are encapsulated in double quotes.

Completely ignoring the last sentence, I decided to change the problem itself to the following:

I want to split the string based on commas that are preceded by no double quotes or scattered pairs of double quotes.

Example:

text,"some,"chars,chars"more,""text",
    *     x      *          x       *

Where * are matches and x is not.

Is this beyond the ability of a regex, and if not, is there a regular expression that can process this kind of input?

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top