关于Regular Expression我想说的

今天看到一道题目,想了许久都没有想出来,事后觉得自己对.net里的RE还不是很熟悉。
题目是这样的:
要把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);



看来是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.


原文地址:https://www.cnblogs.com/buhaiqing/p/1199131.html