【问题标题】:Regex Get Everything Between 2 Words正则表达式获取 2 个单词之间的所有内容
【发布时间】:2021-06-28 09:50:13
【问题描述】:

我需要在文本中找到最后一个匹配词“Madhuparna”,并获取左侧接近匹配标记 html 到文本中最后一个标记 html 之间的文本。

  • 要查找的单词:

Madhuparna

  • 文字输入:

<p>The entire purpose speed up the process.</p><p>June 5, 2021 By Demo</p>\r\n<p>The entire purpose of a terminal emulator is to imitate how the regular computer terminals perform</p><p>Allowing the main computer to connect Madhuparna to and use a remote computer</p><li>bla bla bla bla bla bla</li>

  • 我需要的结果:

<p>Allowing the main computer to connect Madhuparna to and use a remote computer</p><li>bla bla bla bla bla bla</li>

  • 我现在必须做但不能工作:

/<(\S+)(>| .*?>)[^<>]*Madhuparna[^<>]*<\/\1>/g

【问题讨论】:

    标签: regex uipath


    【解决方案1】:

    你可以使用

    (?s)<\w+(?:\s[^>]*)?>[^<>]*Madhuparna.*</\w+>
    

    请参阅regex demo详情

    • (?s) - 内联 singleline 标志
    • &lt; - &lt; 字符
    • \w+ - 一个或多个单词字符
    • (?:\s[^&gt;]*)? - 可选出现一个空格,然后是 &gt; 以外的零个或多个字符
    • &gt; - 一个 &gt; 字符
    • [^&lt;&gt;]* - 除&lt;&gt; 之外的零个或多个字符
    • Madhuparna - 一个子字符串
    • .* - 任何零个或多个字符,尽可能多
    • &lt;/\w+&gt; - &lt;/ 字符串,任何一个或多个单词字符,&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2023-03-19
      • 1970-01-01
      • 2018-12-21
      相关资源
      最近更新 更多