2013-11-15 26 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 
相关问题