代码之家  ›  专栏  ›  技术社区  ›  eozzy

在标记开始和结束之间查找特定单词

  •  0
  • eozzy  · 技术社区  · 3 年前

    我需要找个词 this <template> </template> :

    <template>([this])*?<\/template>

    https://regex101.com/r/VmGESa/1

    2 回复  |  直到 3 年前
        1
  •  1
  •   plalx    3 年前

    您不需要多行 m 旗帜和 .

    例如。

    <template>(?:.|\r|\n)*?(this)(?:.|\r|\n)*?<\/template>

    https://regex101.com/r/krkP9d/1

        2
  •  0
  •   Green grün 绿色 vert зеленый    3 年前

    正则表达式正在匹配

    • 我们从 <template>
    • t , h i s 具有任意长度,例如。, thssiththissiththhtht ([this])*
    • 以…结束 </template>

    这个解决方案对你有用吗?

    <template>(?:.|\n|\r)*(this)(?:.|\n|\r)*<\/template>
    

    .* \n \r 使用OR运算符 | . (?:...)