c# - How to replace single quotes string with literal if it contains escaped single quotes? -
i need escape single quotes strings literals , using following regular expression:
'[^']*'
it working fine, except when have escaped single quotes in string must replaced itself. example, following string:
[compute:{iif([client name] '%happy%', 'happy\'s', 'other\'s jr.')}]
i have these matches:
%happy% happy\ , s jr.
i can replace \'
other sequence of characters (for example internal_value
) , perform string replacement, more clearer if can regular expression instead.
you need negative behind. use lazy match .*?
can put negative behind backslash (?<!\\)
before end single quote.
var reg = new regex(@"'.*?(?<!\\)'"); foreach(match m in reg.matches(@"[compute:{iif([client name] '%happy%', 'happy\'s', 'other\'s jr.')}]")) console.writeline(m);
outputs
'%happy%'
'happy\'s'
'other\'s jr.'
Comments
Post a Comment