题目是这样的:
要把HTML里的LINK标记去掉,比方说输入是<a href=\"abc.com\" />text</a>,期望的输出就是text
在网上找了不少资料才得到答案。
1 string input = "<a href=\"abc.com\" />text</a>d";
2 Console.WriteLine(input);
3 Match omatch = rg.Match(input);
4 input = System.Text.RegularExpressions.Regex.Replace(input, "<a[^>]+>([^<]+)</a>", "$1");
5 Console.WriteLine(input);
2 Console.WriteLine(input);
3 Match omatch = rg.Match(input);
4 input = System.Text.RegularExpressions.Regex.Replace(input, "<a[^>]+>([^<]+)</a>", "$1");
5 Console.WriteLine(input);
看来是Regex.Replace的第三个参数还不熟悉它的用法。
Character |
Description |
---|---|
$number |
Substitutes the last substring matched by group number number (decimal). |
${name} |
Substitutes the last substring matched by a (?<name> ) group. |
$$ |
Substitutes a single "$" literal. |
$& |
Substitutes a copy of the entire match itself. |
$` |
Substitutes all the text of the input string before the match. |
$' |
Substitutes all the text of the input string after the match. |
$+ |
Substitutes the last group captured. |
$_ |
Substitutes the entire input string. |