正規表示式傳回兩個單字之間的多行 - Powershell

正規表示式傳回兩個單字之間的多行 - Powershell

我正在嘗試使用以下正規表示式:

(?<=----Old-------\n)(((.+\n)+)\n*?)(?=__________________________________________)

獲得多行投注

----Old-------
250096 - LT Security Role: Read Only, 250032 - Sales VIC3, 250083 -
Security Role: Base Security Role, 250080 - Security Role: Payment
Allocation, 250058 - Security Role: TFM Sales Consultant, 250103 - Web
Fleet SuperUser

但選擇字串沒有回傳任何內容。

我用了https://regex101.com/https://www.regexpal.com/並且正則表達式正在按預期工作。

能否請你幫忙。

$ModifyOldRegex = "(?<=----Old-------\n)(((.+\n)+)\n*?)(?=__________________________________________)"    
$Description | Select-String  -Pattern $ModifyOldRegex.matches.Value

在此輸入影像描述

答案1

最後我發現了問題:

1-使用 get-Content -Raw 讓 \n 工作 // 我不知道為什麼

2-將正規表示式變更為

“(?<=----舊--------)((.+\n)+)(?=________________________________________________________)”

相關內容