Krishna Krishna - 2 months ago 13
C# Question

Remove not used Merge tags Regular expression

I am using C# and writing mail merge application. My users store the templates as follows

Dear [[-UserName-]],
You have been subscribed for [[-SubscriptionName-]]...


and so on. There will be lot of custom fields between
[[-xxxxx-]]
place holders. I am merging them fine. But sometimes they don't pass for some place holders. I would like to find those things using regular expressions and replace them with empty strings.

Technically, I want to find out the regular expression to find
[[-what ever it is in between-]]
and replace with empty string along with
[[--]]
tags

Jan Jan
Answer

You can use:

\[{2}(-.*?-)\]{2}
# look for [[-, -]] and anything in between.

This is called a lazy dot star, see a demo on regex101.com.

Comments