我需要在給定檔案名的最后一個下劃線之前找到 5 個整數。
示例字串:
X130874_W907025343_Txt.pdf
我需要找到 25353
我最接近的是 (?<=_)[^_] (?=[^_](.{5})_)
uj5u.com熱心網友回復:
在匹配下劃線的 5 位數字后使用前瞻,后跟沒有下劃線,直到最后。
\d{5}(?=_[^_]*$)
uj5u.com熱心網友回復:
利用
[0-9]{5}(?=_(?!.*_))
請參閱正則運算式證明。
解釋
--------------------------------------------------------------------------------
[0-9]{5} any character of: '0' to '9' (5 times)
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
_ '_'
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
.* any character except \n (0 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
_ '_'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
) end of look-ahead
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/410293.html
標籤:
上一篇:需要基于檔案嵌套陣列聚合回傳結果
