![](/img/trans.png)
[英]Street Regex - how do I match a specific word if it appears after another specific word, but not if it occurs before?
[英]How to get lines after the word match and before other specific word?
我有這個字符串:
概觀
有人要求審查
標題
測試
測試
解析度
我想獲得“ 概述 ”一詞之后和“ 解決方案 ”一詞之前的所有內容
我嘗試過此正則表達式: Overview.*[\\r\\n]+(.*)
似乎有點過分,但是嵌套的重復組和實際邊界詞應該非常健壯:
Overview[\r\n]((?:.*[\r\n].*)*)Resolution
JS演示:
const data = `Something Overview Somebody request a review Title Test Test Resolution Blah Something` const after = "Overview" const before = "Resolution" const regex = new RegExp(`${after}[\\r\\n]((?:.*[\\r\\n].*)*)${before}`) const match = data.match(regex) if (match) console.log(match[1])
Regex101的演示和說明: https ://regex101.com/r/QibhMq/6
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.