我只想捕獲內部包含“零容忍”、“突然出現”、“變化與休息一樣好”等值的日志。我已經嘗試過,但它不起作用,它只捕獲第一個。/description=(?零容忍 | 晴天霹靂 | 改變不如休息)
請記住,要檢查的字串需要由我提供。
code = random05, description=bird in the hand is worth two in the bush, level=5
code = random02, description=bolt from the blue, level=8
code = random09, description=bunch of fives, level=3
code = random05, description=A chain is only as strong as its weakest link, level=0
code = random08, description=A change is as good as a rest, level=3```
There are more logs but they are not showing.
uj5u.com熱心網友回復:
看起來您想要匹配description包含您指定的字串之一的任何內容。然后你可以使用
description=(?<des>.*(?:Zero tolerance|bolt from the blue|A change is as good as a rest).*)
因此,在這里,“des”組將盡可能多地匹配除換行符之外的任何零個或多個字符,然后是指定字串之一(注意周圍的空格|被洗掉),然后再匹配除 line 之外的任何零個或多個字符盡可能多地破壞字符。
如果您需要通過第一個逗號限制匹配,請替換.為[^,].
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/437255.html
