Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.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#_Regex_String - Fatal编程技术网

查找注释的C#正则表达式

查找注释的C#正则表达式,c#,regex,string,C#,Regex,String,因此,我删除了[5][12]这样的字符串,这两个括号中的数字介于usign C#之间。我想知道C#正则表达式在执行时要使用什么。我尝试了以下方法: @"\[[0-9]{1,4}\]" 我原以为这会奏效,但没有任何帮助?根据正则表达式工具@,你的注册表很好。但是我认为您需要删除“@”,因为您正在使用“\”转义字符作为转义字符 我刚刚编写并测试了以下代码,它工作得很好(在我的机器上:) 从控制台应用程序运行时…请尝试以下操作: string test = "strings like [5]

因此,我删除了[5][12]这样的字符串,这两个括号中的数字介于usign C#之间。我想知道C#正则表达式在执行时要使用什么。我尝试了以下方法:

@"\[[0-9]{1,4}\]"

我原以为这会奏效,但没有任何帮助?

根据正则表达式工具@,你的注册表很好。但是我认为您需要删除“@”,因为您正在使用“\”转义字符作为转义字符

我刚刚编写并测试了以下代码,它工作得很好(在我的机器上:)

从控制台应用程序运行时…

请尝试以下操作:

    string test = "strings like [5] [12]";
Regex getBrackettedText = new System.Text.RegularExpressions.Regex(@"\[\d+\] \[\d+\]");
string[] values = getBrackettedText.Match(test).Value.Split();

Regex getNumber = new System.Text.RegularExpressions.Regex(@"\d+");

foreach(string value in values)
{
    Console.WriteLine(int.Parse(getNumber.Match(value).Value));
}

我测试了以下内容

        string str = "John[1234]is [2]a foo[944]l";
        string o = Regex.Replace(str, @"\[[0-9]+\]","");
        Console.WriteLine(o);
这看起来是正确的,并且有效(根据),问题可能在代码的其余部分。这对我使用C#regex帮助很大:不,他需要@,因为他使用了“\”字符(这是regex的转义字符,而不是C#)。
        string str = "John[1234]is [2]a foo[944]l";
        string o = Regex.Replace(str, @"\[[0-9]+\]","");
        Console.WriteLine(o);