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 "; }';
here is one that work with both " and ' and you easily add others at the start.
it uses the backreference (\1) match exactley what is in the first group (" or ').
http://www.regular-expressions.info/backref.html
Works in The Regex Coach and PCRE Workbench.
Example of test in JavaScript:
Taken straight from
man perlre
on a Linux system with Perl 5.22.0 installed. As an optimization, this regex uses the 'posessive' form of both+
and*
to prevent backtracking, for it is known beforehand that a string without a closing quote wouldn't match in any case.