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
Post a Comment