Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex: ignore double single quotes if they are within matching substring

I have the string like this:

 'Code1','Code2','Co''de' , 'CodeTest2'

From that string I would like to get four strings Code1, Code2, Co”de and CodeTest2.
I have almost working regex which is: ‘([^’]*)’
The problem is that my regex should ignore quotes if there are next to each other like in the fire string. Is there any way to exclude double- single quotes from the regex?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You might write the pattern as

'(.*?)'(?=\s*,|$)

See a regex demo

Of without the lookahead:

'([^']*(?:''+[^']*)*)'

Regex demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading