7

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

3 Answers 3

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

should take care of that.

Sign up to request clarification or add additional context in comments.

Comments

1

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

\^+\|

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

Comments

1

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

1 Comment

^ will be interpreted as an anchor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.