Answer the question
In order to leave comments, you need to log in
How to find all commas except those in quotes?
Good afternoon.
There is this text: 1,',',2,'text','word, word2'
How can I find all the commas in this text, except those in single quotes?
Answer the question
In order to leave comments, you need to log in
Varies, depending on the environment/language where the regular expressions are executed.
Usually in several stages, and not even always reg. expressions are needed/suitable.
When using the same reg. expressions, it is desirable to rely on some specific conditions (for example, no more than one comma inside quotes). In general terms, this will be a parser, not a regular expression. But even the parser will have to decide on the conditions, otherwise, in general, it will need to be able to parse this:
,1, ','_,2,'text',x'word, ''\'\\word2'
find all commas in this text, except those in single quotes
(?:[^,']*'[^']*'[^,']*|[^,']*)(,)(?:[^,']*'[^']*'[^,']*|[^,']*)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question