2013-11-15 25 views

回答

2

I'd like to match all digits that are in front of the character K and extract that value.

你應該使用:

\d+(?=K) 

(?=K)是正向前查找,使得確保數字後跟K

+0

是先行不僅僅是'\ d + K'更好?如果是這樣,爲什麼? – Cruncher

+0

@Cruncher:好問題。答案是,OP想要提取數字並向前查看,從而節省了對數字進行分組以及從中捕獲「$ 1」的額外步驟。 – anubhava

2

我會使用這樣的:如果你想捕捉的數字

\d+K 

(\d+)K 
相關問題