Regex to extract attribute value

后端 未结 2 748
不知归路
不知归路 2020-12-15 11:07

What would be a quick way to extract the value of the title attributes for an HTML table:

...
  • Procl
  • 2条回答
    •  既然无缘
      2020-12-15 11:46

      This C# regex will find all title values:

      (?<=\btitle=")[^"]*
      

      The C# code is like this:

      Regex regex = new Regex(@"(?<=\btitle="")[^""]*");
      Match match = regex.Match(input);
      string title = match.Value;
      

      The regex uses positive lookbehind to find the position where the title value starts. It then matches everything up to the ending double quote.

    提交回复
    热议问题