I have tried to remove a the "Admin" word in this string
1H|\^&|||ARCHITECT^8.10^F3453010030^H1P1O1R1C1Q1L1|||Admin||||P|1|20150511083525
1D
with this regex
[^\w\b(Admin\])\b.-]+
and the output is 1H|ARCHITECT|8.10|F3453010030|H1P1O1R1C1Q1L1|Admin|P|1|20150511083525|1D
it does not remove the Admin word.
output desired:
1H|ARCHITECT|8.10|F3453010030|H1P1O1R1C1Q1L1|P|1|20150511083525|1D
i need help to improve the regex :(
Basically your regex should be like this
string input = @"1H|\^&|||ARCHITECT^8.10^F3453010030^H1P1O1R1C1Q1L1|||Admin||||P|1|20150511083525
1D";
string pattern = @"([^\w]*Admin[^\w]*)+|[|\\^&\r\n]+";
string replacement = "|";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With