user1179180
user1179180

Reputation: 3

Remove pluses, dashes, colons using REGEX and C#

I need to remove these occurrences in a document using REGEX and C#. They are: +-------------+ (there can be any number of dashes between plus signs) : : (there can be any number of spaces between colons) I cannot remove standalone dashes or semi-colons since they may come after Name: or Address: and are needed. I cannot remove a colon between words with a space on either side. The colon with spaces creates formatting that I need to remove. The plus with dashes in-between creates a line or part of a box that I need to remove.

Basically, I need to remove all dashes with pluses at the ends, including removing the pluses. I also need to remove all spaces with colons at each end, including removing the colon. All other pluses and colons need to remain. This is a medical text file so I need to be careful. I do not have any code to show you since nothing I have tried has come close to working. Thanks for any assistance!

Upvotes: 0

Views: 2427

Answers (1)

Mark Byers
Mark Byers

Reputation: 837946

You can use the following regular expression with Regex.Replace:

s = Regex.Replace(s, @"\+-+\+|: +:", "");

See it working online: ideone

Upvotes: 2

Related Questions