Reputation: 5355
What is regex to match the last single quote in a string that is really single ( i mean it does not have any partner back) so we should get last quote in the:
foo('bar').baz("foo'foo").bar('baz').foo('bar
but nothing to match in the following:
foo('bar').baz
Upvotes: 0
Views: 65
Reputation: 8332
I believe this is quite a complex task, especially since you're involving double quotes. But you might make it work with something like this:
^('[^']*'|"[^"]*"|[^'"])*$
From the start of the string, it matches either
Then it goes on 'til the end of the string. If it encounters unbalanced quotes, it fails.
I'm pretty sure this will fail in many cases, but the simplest ones should work.
Edit: In the example I had to put newline - \n
- in negated classes as well to illustrate several examples.
Upvotes: 1