user1380769 user1380769 - 4 months ago 6
C# Question

Regex to replace multiple instances of "tokens" in the following format: [[TokenName:TokenValue]]?

I'm looking for a Regex that can replace any instance of

[[Something:SomethingElse]]
with an empty string.

Answer

Try this regex: \[\[.*?:.*?\]\]

string str = @"some string before pattern [[Something:SomethingElse]] between
               pattern [[doesnt matter:at all]] after pattern";
string result = Regex.Replace(str, @"\[\[.*?:.*?\]\]", "");

Outout:

some string before pattern  between pattern  after pattern