I need help to remove the characters in this line(the ^ & and \\) and also the empty values in between them, im new to regex
1H|\^&|||ARCH^8.10^F3453010030^H1P1O1R1C1Q1L1|||||||P|1|20150511083525
1D
it should be:
1H|ARCH|8.10|F3453010030|H1P1O1R1C1Q1L1|P|20150511083525|1D
对于给定的字符串,您可以使用以下内容替换这些字符。
String result = Regex.Replace(input, @"[^\w.]+", "|");
[\^&\\|]+
Try this.Replace by |
.See demo.
https://regex101.com/r/oF9hR9/6
string strRegex = @"[\^&\\|]+";
Regex myRegex = new Regex(strRegex, RegexOptions.Multiline);
string strTargetString = @"1H|\^&|||ARCHITECT^8.10^F3453010030^H1P1O1R1C1Q1L1|||||||P|1|20150511083525" + "\n" + @"1D";
string strReplace = @"|";
return myRegex.Replace(strTargetString, strReplace);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.