zoukankan      html  css  js  c++  java
  • 关于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.


  • 相关阅读:
    (二十四)JSP标签之基本标签(<jsp:标签名>)
    (二十三)JSP指令
    (二十二)JSP基础语法
    (二十一)JSP基础
    java类的初始化过程
    redis的主从复制和哨兵支持的主从切换
    redis事务和乐观锁
    redis的持久化
    linux修改进程的名字
    在c代码中获取用户环境变量
  • 原文地址:https://www.cnblogs.com/buhaiqing/p/1199131.html
Copyright © 2011-2022 走看看