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

Match every character that is not is inside quotes in RegEx Dart

I’m working in a project in Dart, and I need a RegEx to match every single character of the character set [a-zA-Z0-9] that is not inside single quotes, for example:

Hello my 'name' is

I want it to match "Hello my" and "is", but the RegEx needs to be versatile enough to encompass every situation instead of a specific pattern, the only thing I need to achieve is to match every character outside of single quotes.

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 can use allMatches to find all non-' characters ([^']) that are not in a quote ('[^']*').

RegExp r = RegExp(r"([^']*?)($| *'[^']*' *)");
print(r.allMatches("Hello my 'name' is").map((m) => m.group(1)));

Results in "Hello my" and "is" as in your example.

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