Rise_against
Rise_against

Reputation: 1060

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

Upvotes: 7

Views: 4669

Answers (3)

hometoast
hometoast

Reputation: 11782

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

should take care of that.

Upvotes: 7

siukurnin
siukurnin

Reputation: 2902

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

Upvotes: 1

ChrisNel52
ChrisNel52

Reputation: 15143

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

\^+\|

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

Upvotes: 1

Related Questions