c# - Replace a pattern in string only if a certain condition is satisfied - Regex -


how can replace ' \\' in string. (this can done using regex.ismatch(), regex.matches(), regex.replace() however, should done if ' doesn't have \ or \\ before already. (this stuck)

that means find ' not have \ or \\ before , add same, i.e. ' replace \\'

example string: 'abcd\'efg'hijkl'mno\\'pqrs'

resulting string: \\'abcd\\'efg\\'hijkl\\'mno\\'pqrs\\'

no need regex, even.

var newstr = oldstr.replace("\\'", "'").replace("'", "\\'"); 

with regex, can find ' don't have \\ before them with:

[^\\]' 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

ruby - Nesting modules inside of a Rails eninge gem -

Eclipse formatter for java ending braces -