How can i replace any word but one in a string using C# regex? -
given string this: fixing [hfw] takes alot of [hfw] time [hfw]
should this: [cw] [cw] [hfw] [cw] [cw] [cw] [hfw] [cw] [hfw]
i need replace word [cw] except tags [hfw]. i've been trying alot, best got is:
regex = new regex(@"[^(\[hfw\])_]+"); cleantext = regex.replace(cleantext, " [cw] "); which works, first capital f left out, being part of [hfw] tag. mean, won't take [hfw] group.
thank you
i've got 1 bit... cranky? trick sample string:
(?<!\[|f|\[f)\w+(?!w|\]|w\]\]) the issue [^...] doesn't @ order of characters \[, h, f, w or \].
there's more elegant 1 , i'm still trying it.
another possible one:
\w+(?=\s)|(?<=\s)\w+
Comments
Post a Comment