2016-12-07 83 views
1

我試圖獲取兩個特定匹配項之間的字符串,例如兩個hashtags。正則表達式返回兩個匹配項之間的字符串

我想什麼來實現:

輸入:some text in front ##hi there## some text behind

輸出:hi there

隨着/%%(.*)%%/,則返回##hi there##

在此先感謝

+0

,什麼是語言? –

+0

@WiktorStribiżew對不起,我不知道這是相關的。這是PHP – nickosv

+2

只要訪問'$匹配[1]' –

回答

0

您需要向前看,並且看後面。

(?<=##).*(?=##) 

這將匹配hi there

https://regex101.com/r/qUR4NR/1

+0

如果我想要多個匹配,比如說字符串是'there %% are %% two %% matches %% now' – nickosv

相關問題