Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C中特定格式的正则表达式模式#_C# - Fatal编程技术网

C# C中特定格式的正则表达式模式#

C# C中特定格式的正则表达式模式#,c#,C#,我有一个类似于Test(123)Test的字符串,需要从字符串中删除(123) 请帮我得到那个回复的确切正则表达式模式 Input : Test(123)Test Output: Test Test 谢谢,Gunasekaran Sambandhan试试下面的方法。。。它会帮助你 代码: string input = "Test(123)Test"; string regex = "(\\(.*\\))"; string sOutput = Regex.Replace(input, regex

我有一个类似于
Test(123)Test
的字符串,需要从字符串中删除
(123)

请帮我得到那个回复的确切正则表达式模式

Input : Test(123)Test
Output: Test Test

谢谢,Gunasekaran Sambandhan

试试下面的方法。。。它会帮助你

代码:

string input = "Test(123)Test";
string regex = "(\\(.*\\))";
string sOutput = Regex.Replace(input, regex, " ");
Console.WriteLine(sOutput);
string input = "(hi) (91) Professional Investment Services Pty Ltd (hi) (91)";
Regex regex = new Regex(string.Format("\\{0}.\\d+\\{1}", '(', ')'));
Console.WriteLine(regex.Replace(input, string.Empty));
(hi) Professional Investment Services Pty Ltd (hi)
输出:

Test Test
更新代码:

string input = "Test(123)Test";
string regex = "(\\(.*\\))";
string sOutput = Regex.Replace(input, regex, " ");
Console.WriteLine(sOutput);
string input = "(hi) (91) Professional Investment Services Pty Ltd (hi) (91)";
Regex regex = new Regex(string.Format("\\{0}.\\d+\\{1}", '(', ')'));
Console.WriteLine(regex.Replace(input, string.Empty));
(hi) Professional Investment Services Pty Ltd (hi)
输出:

string input = "Test(123)Test";
string regex = "(\\(.*\\))";
string sOutput = Regex.Replace(input, regex, " ");
Console.WriteLine(sOutput);
string input = "(hi) (91) Professional Investment Services Pty Ltd (hi) (91)";
Regex regex = new Regex(string.Format("\\{0}.\\d+\\{1}", '(', ')'));
Console.WriteLine(regex.Replace(input, string.Empty));
(hi) Professional Investment Services Pty Ltd (hi)

你已经试过什么了?到目前为止你试过什么了?:)你知道,如果你想得到我们的帮助,也许先表现出一些努力。。。如果更多的人看到你只是不坐下来等待答案,他们会愿意提供帮助。问题还在于你没有清楚地解释你需要什么,作为一名程序员/工程师,你应该知道你需要具体。字符串总是有
(123)
那么你的答案就是
inString.Replace(“(123)”,”)或括号内有一些数字,或正好是3个数字?你希望我们回答所有的排列吗?我希望你能理解这是多么令人沮丧。我猜他在括号上有问题。如果他有问题的话,他应该花时间在他的问题中表达出来。谢谢潘迪安。但是它截断了(123)@gunaSamba之后的所有字符:不,它对我来说非常有效。。你能在你的项目中粘贴相同的代码并看到结果吗?…以下输入“(91)Professional Investment Services Pty Ltd(91)”生成空输出Hanks pandian。。它对我有用。。但是我只想在格式中包含数字时替换它..我使用以下模式得到它:Regex regexpatern=new Regex(string.format(“\{0}\\d+?\{1}”,'(','));。。。谢谢你的支持