2012-02-03 53 views
1

鑑於以下文字:正則表達式來檢索之間的一切「|描述=」和「|類別」

|Description=This is the start of the ... 

... <strong>description</strong> of a product that can span over multiple lines 
|Category=Product 

如何取回之間文|說明=|分類=產品

在上面的例子中,返回的字符串應該只包含:

This is the start of the ... 

... <strong>description</strong> of a product that can span over multiple lines 

回答

3

使用此模式

(?<=\|Description=)(.*)(?=\|Category) 

運行它dot allmultiline標誌。

+0

謝謝,這是工作。出於興趣,爲什麼會preg_match('/(?<= \ | Description =)(。*)(?= \ | Category)/ sm',$ text,$ matches))返回一個包含兩個重複返回字符串的數組? – 2012-02-03 08:50:58

+0

@MichaelP:對不起,我不知道爲什麼可能是:( – 2012-02-03 09:30:35

1

使用此模式\|Description=(.*?)\|Category=

+0

你應該逃避'|' – bummzack 2012-02-03 08:41:14

+0

是的,我只是編輯答案 – shift66 2012-02-03 08:42:18

+0

仍然錯誤..你應該只用一個反斜槓 – bummzack 2012-02-03 09:03:31

相關問題