---
title: "Issue with Regex Replace"  
description: "Issue with Regex Replace"  
author: "Anonymous User"  
published: 2013-12-27  
updated: 2013-12-27  
canonical: https://www.mindstick.com/forum/1848/issue-with-regex-replace  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Issue with Regex Replace

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [replace](https://yourviews.mindstick.com/view/81330/cow-antibody-research-in-usa-a-step-ahead-to-replace-plasma-therapy) every occurrence of "]}]" (ignore the quotes) using the Regex [object in C#](https://www.mindstick.com/forum/161296/what-is-the-purpose-of-the-history-object-in-c-sharp).

I have set up the Regex Escape value like this:

var regexReplaceVar = new Regex(Regex.Escape("]}]"));

I then call the replace [method as](https://www.mindstick.com/interview/2388/can-you-declare-the-main-method-as-final-in-java) shown below:

myEditedString = regexReplaceVar.Replace(startString, sringToInsert, 1);

It does not appear to be working the way I think it would. Are the [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) I am attempting to replace special to [Regular Expressions](https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table)? Should they be modified to have them be taken as literals?

Thanks in advance.

## Replies

### Reply by Anonymous User

Hi Jeet,

All of the characters you are seeking must be escaped in C# Regex.

## Regex:

\]\}\]

## C#:

```
Regex regexObj = new Regex(@"\]\}\]",
RegexOptions.IgnoreCase);string result = regexObj.Replace(subjectString,
replaceWith);Console.WriteLine(result);
```

result holds the replaced string, this is important because subjectString doesn't change.


---

Original Source: https://www.mindstick.com/forum/1848/issue-with-regex-replace

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
