Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.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
HTML代码中的C#字符串介于两者之间_C#_Regex_String_Replace - Fatal编程技术网

HTML代码中的C#字符串介于两者之间

HTML代码中的C#字符串介于两者之间,c#,regex,string,replace,C#,Regex,String,Replace,我有一个包含以下内容的字符串变量: () 如何在额外变量中获取9736461?字符串总是相同的,只是数字不同 编辑: 我试过: Tag = Regex.Replace(Tag, @"(<b><a href=\"#post"); Tag = Regex.Replace(Tag, @"" title=\"Show\">Permalink</a></b>)"); Tag=Regex.Replace(Tag,@“()”); (?以下代码可以: strin

我有一个包含以下内容的字符串变量:

()

如何在额外变量中获取
9736461
?字符串总是相同的,只是数字不同

编辑:

我试过:

Tag = Regex.Replace(Tag, @"(<b><a href=\"#post");
Tag = Regex.Replace(Tag, @"" title=\"Show\">Permalink</a></b>)");
Tag=Regex.Replace(Tag,@“()”);

(?以下代码可以:

string input = "(<b><a href=\"#post9736461\" title=\"Show\">Permalink</a></b>)";
string value = Regex.Match(input, @"(?<=#post)\d+").Value;
字符串输入=“()”;

字符串值=Regex.Match(输入@”(?使用适当的库进行Html解析。有关详细信息,请参阅example@Steve这个代码段不需要HTML解析库。它的语法是纯XML,因此可以用XML和XPath处理。如果这个小字符串除了数字部分外是不变的,我看不出使用解析库有什么意义。@martin_costello请看我的编辑你需要做的就是抓取数字?如果使用零宽度查找,则无需反向引用。此外,我怀疑这对于不了解正则表达式的人来说是非常清楚的。
resultString = Regex.Replace(subjectString, @"(#post\d+)""", "$1");

Match the regular expression below and capture its match into backreference number 1 «(#post\d+)»
   Match the characters “#post” literally «#post»
   Match a single digit 0..9 «\d+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “"” literally «"»
string input = "(<b><a href=\"#post9736461\" title=\"Show\">Permalink</a></b>)";
string value = Regex.Match(input, @"(?<=#post)\d+").Value;