I have a string that can look like the following:
"1132","Fredricks, Ben","Boulder, CO","x755593"
And I have the following regex which I thought should NOT match:
^"\d+",".*?","[^,]+"
But it matches the entire string. Shouldn’t the [^,]+ which means, I think “match everything thats not a comma up until a quote mark … cause the match to fail? It encounters a comma which I thought would make it not match.
I guess my question is … why does this match? I’m trying to find things inside the 3rd set of quotes that don’t have a comma.
The
?in.*?only makes the match non greedy. Without it the pattern would capture as much as possible while still matching the rest. It was probably added to avoid having that pattern match across a"but it doesn’t prevent it. If you looked at the captured strings (if you matched"(\d+)"etc so$1contain the matches) you’d see that your.*?matched much more than you expected (multiple fields).