我收到此事件文本,我需要能夠決議出每一行的 FQDN 以及方面名稱。我已經嘗試了幾個 FQDN 正則運算式示例,唯一接近的是^[^.] 但仍然只捕獲了主機名,我會很好。但我似乎無法捕獲兩組資料。
例子:
行:Test1.test.local 系統保留 73.2 %
輸出:
FQDN = Test1.test.local
方面名稱 = 系統保留
'Performance Disk Utilization Exceeds 50%' threshold
Description: Average disk utilization during the past 2 minutes exceeds 50%
New Items (11)
Occurred at 10/21/2021 10:38:06 AM
Display Name Aspect Name Aspect Value
Test1.test.local System Reserved 73.2 %
Test1-stage.test.local System Reserved 69.3 %
test-stage.test.local \\?\Volume{c2e5b983-0000-0000-0000-006225000000}\ 83.3 %
test2.test.local System Reserved 73.2 %
test2.test.local E:\ - Data 62.5 %
test.test.LOCAL System Reserved 69.3 %
test.test.LOCAL \\?\Volume{0833abcb-0000-0000-0000-006225000000}\ 83.3 %
test3.test.local System Reserved 69.4 %
test3.test.local E:\ - SCCM 85.7 %
test3.cdp.local C:\ 53.1 %
test3.cdp.local \\?\Volume{fa03c719-0000-0000-0000-f0e17c000000}\ 83.3 %
uj5u.com熱心網友回復:
您可以使用 2 個捕獲組并匹配末尾的數字,后跟一個百分比符號:
([^\s.] (?:\.[^\s.] ) ) (. ?) \d (?:\.\d )? %
(捕獲組 1[^\s.]匹配 1 個字符而不是 whitspace 字符或.(?:\.[^\s.] )重復 1 次匹配一個點,后跟 1 個字符而不是 whitspace 字符或.匹配至少一個點
)關閉第 1 組(. ?)在第 2 組中的 2個空格之間捕獲 1 個或多個數字\d (?:\.\d )? %將 1 位數字與可選的小數部分匹配,然后%
正則運算式演示
const regex = /([^\s.] (?:\.[^\s.] ) ) (. ?) \d (?:\.\d )? %/gm;
const str = `Test1.test.local System Reserved 73.2 %
Test1-stage.test.local System Reserved 69.3 %
test-stage.test.local \\\\?\\Volume{c2e5b983-0000-0000-0000-006225000000}\\ 83.3 %
test2.test.local System Reserved 73.2 %
test2.test.local E:\\ - Data 62.5 %
test.test.LOCAL System Reserved 69.3 %
test.test.LOCAL \\\\?\\Volume{0833abcb-0000-0000-0000-006225000000}\\ 83.3 %
test3.test.local System Reserved 69.4 %
test3.test.local E:\\ - SCCM 85.7 %
test3.cdp.local C:\\ 53.1 %
test3.cdp.local \\\\?\\Volume{fa03c719-0000-0000-0000-f0e17c000000}\\ 83.3 %`;
console.log(Array.from(str.matchAll(regex), m => ({
"FQDN": m[1],
"AspectName": m[2]
})));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/334542.html
標籤:javascript 正则表达式
上一篇:條件格式:具有間接參考的多個條件
