简体   繁体   中英

Remove characters with regex in c#

I am not a regex specialist, so I need some help with this. I have a text file, and I need to remove some trailing delimiters. The text file looks like this:

MSH|^~\&|OAZIS||||20101029135359||ADT^A31|00000015|P|2.3.1||||||ASCII
EVN|A31|20101029135359^^^^||||19900101

So I think the best way is to do a Regex replace? Can anyone help me with this regex?

I want to remove all ^ that come before a |

So test^A^^| has to become test^A|

Thanks

resultString = Regex.Replace(subjectString, @"\^+\|", "|");

应该照顾好。

I belive your regular expression would look like this...

\^+\|

That should match one ore more '^' followed by a '|'.

The regex to match will be something like :

^+\\|

But its dangerous to use regexes you don't understand (just like any other code !)

read some tutorials or you'll miss a lot of things, for example :

http://www.codeproject.com/KB/dotnet/regextutorial.aspx

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM