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

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -