[英]regex for excluding certain phrase from txt.file
我需要從看起來像這樣 +/- 的 txt 文件中檢索數字:
[ Index 1 ]
1628 5704
32801 61605
71508 90612
1026061
我需要忽略 Indexe 的號碼。
[0-9]+
檢索所有數字,索引也是如此。
我嘗試了類似的東西,稱為負前瞻(?![(Index 1)])([0-9]+)
。 它確實忽略了 1,但所有這些……例如 1628 變為 628。感謝幫助,我在正則表達式語法方面一直很弱:/
用
\b(?<!Index )\d+
見證明。
解釋
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
--------------------------------------------------------------------------------
(?<! look behind to see if there is not:
--------------------------------------------------------------------------------
Index 'Index '
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
此模式僅匹配數字。 它在字符串的開頭尋找一個系列或多個數字,或者在一個字符串的末尾尋找系列或多個數字。
^\d+|\d+$
https://regex101.com/r/ZNTxQ7/1
另一種方法是在字符串中查找一系列兩個或多個數字。
\d{2,}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.