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.
>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.