簡體   English   中英

如何在單詞匹配之后和其他特定單詞之前獲得行?

[英]How to get lines after the word match and before other specific word?

我有這個字符串:

概觀

有人要求審查

標題

測試

測試

解析度

我想獲得“ 概述 ”一詞之后和“ 解決方案 ”一詞之前的所有內容

我嘗試過此正則表達式: Overview.*[\\r\\n]+(.*)

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

為此,您需要使用修飾符。 我建議使用

/ s 單行

Overview.*[\r\n]+(.*)/s

在線演示

似乎有點過分,但是嵌套的重復組和實際邊界詞應該非常健壯:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM