Regex to extract attribute value

后端 未结 2 743
不知归路
不知归路 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.

      0 讨论(0)
    • 2020-12-15 11:50

      Use the regexp below

      title="(.[^"]+)"
      

      and then use Groups to browse through matched elements.

      EDIT: I have modified the regexp to cover the examples provided in comment by @Staffan Nöteberg

      0 讨论(0)
    提交回复
    热议问题