我有這個按預期作業的正則運算式。
due (?:\w ){3}community
如這里所見...
https://regex101.com/r/8LDW9v/35
示例文本是:
unfortunately due to the current community size I am not comfortable granting you permanent permissions yet, but I have granted it for 6 months given your experience (normally we start at 3). vote for that. due payment2342 of bill community should be made. and then due to some un community events again due one to three community
但是這個 grep 命令沒有回傳任何東西......
grep -E "(due (?:\w ){3}community)" mytext.txt
uj5u.com熱心網友回復:
使用-P(Perl 正則運算式)標志:
$ grep -oP "due (?:\w ){3}community" test.txt
due to the current community
due payment2342 of bill community
due to some un community
due one to three community
我不確定?:擴展正則運算式是否支持它。如果要使用-E,可以將正則運算式更改為:
$ grep -oE "(due (\w ){3}community)" test.txt
due to the current community
due payment2342 of bill community
due to some un community
due one to three community
但是,這將捕獲組中每個匹配項的第三個單詞。
uj5u.com熱心網友回復:
Grep 不支持非捕獲組,因此您可以將非捕獲組更改為捕獲組并省略模式的外括號,因為該組在模式中沒有用途。
用于-o僅列印匹配的部分。
grep -Eo "due (\w ){3}community" mytext.txt
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/354316.html
上一篇:正則運算式拆分格式不正確的地址
