C#正则判断字符串中以\\\\(开头,以\\\\)结尾的内容,并替换成其他内容
时间: 2024-02-19 22:56:27 浏览: 120
C#正则替换文字
5星 · 资源好评率100%
以下是使用C#正则表达式判断字符串中以\\\\(头,以\\\\)结尾的内容,并替换成其他内容的示例代码:
```csharp
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string input = "This is a (example) string";
string pattern = @"\\\(.*?\\\)";
string replacement = "[replacement]";
string result = Regex.Replace(input, pattern, replacement);
Console.WriteLine("Original string: " + input);
Console.WriteLine("Modified string: " + result);
}
}
```
运行结果:
```
Original string: This is a (example) string
Modified string: This is a [replacement] string
```
阅读全文