Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove characters with regex in c#

Tags:

c#

regex

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

like image 497
Rise_against Avatar asked Jan 11 '11 13:01

Rise_against


2 Answers

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

should take care of that.

like image 136
hometoast Avatar answered Sep 25 '22 05:09

hometoast


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

\^+\|

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

like image 38
ChrisNel52 Avatar answered Sep 23 '22 05:09

ChrisNel52