-2

I want to find occurrences of anything within [[...]] and replace with another string. For example, [[name]] lives in Florida. [[name]] = James

I almost have it working, except for one small issue.

Regex.Replace([[name]], @" ?\[[.*?\]]", "James")

The output is: James] lives in Florida. The last ] is not being replaced.

Jay
  • 329
  • 1
  • 6
  • 22

1 Answers1

0

You need to escape both opening square brackets (and closing square brackets don't need): \[\[.*?]].

Pac0
  • 21,465
  • 8
  • 65
  • 74