How do I get the substring " It's big \"problem "
using a regular expression?
s = ' function(){ return " It\'s big \"problem "; }';
How do I get the substring " It's big \"problem "
using a regular expression?
s = ' function(){ return " It\'s big \"problem "; }';
A more extensive version of https://stackoverflow.com/a/10786066/1794894
This version also contains
“
and close”
)Messed around at regexpal and ended up with this regex: (Don't ask me how it works, I barely understand even tho I wrote it lol)
If it is searched from the beginning, maybe this can work?
As provided by ePharaoh, the answer is
To have the above apply to either single quoted or double quoted strings, use
Alternating the
\"
and the.
passes over escaped quotes while the lazy quantifier*?
ensures that you don't go past the end of the quoted string. Works with .NET Framework RE classesThis one works perfect on PCRE and does not fall with StackOverflow.
Explanation:
"
;.*?
{Lazy match}; ending with non escape character[^\\]
;(.*?[^\\])??
"
), but it can be preceded with even number of escape sign pairs(\\\\)+
; and it is Greedy(!) optional:((\\\\)+)?+
{Greedy matching}, bacause string can be empty or without ending pairs!