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

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -