• 关于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.


  • 相关阅读:
    SQLi-Labs
    ASP.NET 简介
    CSS
    Apache 基本配置
    【Windows 基础】 01
    sqli1-4
    SQL注入介绍(本文更新中)
    【DC-1】靶机实战
    常见端口的漏洞总结
    element ui table动态控制某列展示与否,并且该列使用了fixed,导致列表错位问题
  • 原文地址:https://www.cnblogs.com/buhaiqing/p/1199131.html
Copyright © 2020-2023  润新知