zoukankan      html  css  js  c++  java
  • ASP.net:Regex.Match 方法 中应该注意的几个问题

    一、概述

          Regex.Match 方法

          在输入字符串中搜索正则表达式的匹配项,并将精确结果作为单个 Match 对象返回。

          重载列表
          (1) 在指定的输入字符串中搜索 Regex 构造函数中指定的正则表达式匹配项。

                     [C#] public Match Match(string);

         (2) 从指定的输入字符串起始位置开始在输入字符串中搜索正则表达式匹配项。

                   [C#] public Match Match(string, int);

         (3) 在指定的输入字符串中搜索 pattern 参数中提供的正则表达式的匹配项。

                  [C#] public static Match Match(string, string);

         (4)   从指定的输入字符串起始位置开始在输入字符串中搜索具有指定输入字符串长度的正则表达式匹配项。

               [C#] public Match Match(string, int, int);

       (5)    在输入字符串中搜索 pattern 参数中提供的正则表达式的匹配项(匹配选项在 options 参数中提供)。

              [C#] public static Match Match(string, string, RegexOptions);

      二、应用举例

       1.下面的代码是为了取出网页中的Title属性

            Match TitleMatch = Regex.Match(fileContents, "<title>([^<]*)</title>", RegexOptions.IgnoreCase | RegexOptions.Multiline );

            filetitle = TitleMatch.Groups[1].Value;

         注意红色的1, Regex.Match方法得到的Groups的索引是从1开始的,而不是从0开始的

     2. 下面的代码是为了取出网页头部的"Content"属性

                  Match DescriptionMatch = Regex.Match( fileContents, "<META NAME=\"DESCRIPTION\" CONTENT=\"([^<]*)\">", RegexOptions.IgnoreCase | RegexOptions.Multiline );
                  filedesc = DescriptionMatch.Groups[1].Value;

  • 相关阅读:
    CF 561 div2 C
    CF #560 div3
    1.11 acm结束了,所以寒假学习Java基础
    11.5 cometoj #12 -- D XOR Pair (数位dp)
    11 .3 数位dp
    10.1 叉积 ,极角排序,扫描法求凸包
    9.11 状态矩阵 与 dp
    9.3 整理一下最短路算法
    9.3 欧拉定理 && 欧拉降幂 (扩展欧拉定理)&& 指数循环节
    Two Arithmetic Progressions (exgcd的一些注意事项
  • 原文地址:https://www.cnblogs.com/ymyglhb/p/1263520.html
Copyright © 2011-2022 走看看