我需要this在<template>and 中找到一個詞</template>:
我試過了,<template>([this])*?<\/template>但似乎不起作用。
https://regex101.com/r/VmGESa/1
uj5u.com熱心網友回復:
您不需要多行m標志并且.不匹配換行符,因此您必須考慮到這一點。
例如
<template>(?:.|\r|\n)*?(this)(?:.|\r|\n)*?<\/template>
https://regex101.com/r/krkP9d/1
uj5u.com熱心網友回復:
您的正則運算式匹配的字串
- 開始于
<template>, - 隨后的字符的任意組合
t,h,i或s具有任意的長度,例如,thssiththissiththhtht將由匹配([this])*, - 以
</template>,結尾
這個解決方案對你有用嗎?
<template>(?:.|\n|\r)*(this)(?:.|\n|\r)*<\/template>
.*匹配任意數量的任意字符,新行除外。所以,我用 OR 運算子添加了\n和。意味著,它是一個非捕獲組,即在請求組時,該組不會出現。\r|(?:...)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/340826.html
標籤:javascript 正则表达式
