簡體   English   中英

RegExp用於多行-匹配並捕獲唯一的輸出

[英]RegExp for multiple lines - matching and capturing unique output

* A:DUT-C#顯示統計信息gx

output of above command

* A:DUT-C#顯示統計信息gy

output of above command

* A:Dut-C#顯示狀態s11

output of above command

* A:Dut-C#顯示狀態s12

output of above command

* A:DUT-C#顯示狀態s5

output of above command

* A:DUT-C#顯示狀態s1u

output of above command

* A:DUT-C#


如果我想在一個巨大的文件中搜索上述字符串,然后捕獲每個接口的輸出(gx,gy,s11,s12,s5,s1u等)統計信息,則正則表達式將是什么?

我嘗試了以下正則表達式,但仍不完整:

*/([*A-Za-z]:Dut-[a-zA-Z]{1}#\sshow stats\s(gx|gy|s11|s12|s5|s1u)|[\r])/g*

無法弄清楚該怎么做。

此解決方案有效:

A:Dut-C#\sshow\sstats\s(\w+)[$\s\n]+([=\n:a-zA-Z0-9! \-\.]+\* indicates that the corresponding row element may have been truncated.)

標志:全球

演示: https : //regex101.com/r/gl5aHA/5

您的模式似乎有效。 您需要查看第1組以找到捕獲的字符串。

這是一個替代解決方案:

a:dut-\\w#\\sshow\\sstats\\s(\\w+)

  • 標志:全局,不區分大小寫
  • 步驟:164

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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