preg_match_all匹配整个句子

时间:2012-08-23 03:33:48

标签: php preg-match-all

我试图得到整个句子:

PRICE CHANGE this this : this var1 : this/this (this) var2,var3 : 111,11 Price(€) : 1.021 start from : 2012-07-26 18:15:00

自:

timezone. PRICE CHANGE this : this var1 : this/this(this) var2, var3 : 119, 111 Price(€) : 5.021 start from : 2012-07-26 18:15:00 PRICE CHANGE this : this this2 var1 : this (this ) var2, var3 : 1604, 452 Price(€) : 6.014 start from : 2012-07-26 18:15:00 bla bla bla bla.

使用此:

body = "timezone. PRICE CHANGE this : this var1 : this/this(this) var2, var3 : 119, 111 Price(€)     : 5.021 start from : 2012-07-26 18:15:00 PRICE CHANGE this : this  this2 var1 : this  (this ) var2, var3 : 1604, 452 Price(€)   : 6.014 start from : 2012-07-26 18:15:00 bla bla bla bla."

$test = preg_match_all('/PRICE CHANGE\s*(.*?)*(\d+:\d+:\d+)', $body, $result);

它没有用,有帮助吗?

2 个答案:

答案 0 :(得分:1)

preg_match_all('/PRICE CHANGE.*?(?=PRICE CHANGE)/', $body, $result);

除非你没有告诉我们有关结构的事情,否则会做到这一点。如果它真的只是一个价格变化列表,那么这将做三重奏并且更具可读性。

'(?='如果您不知道,是一个先行。它是一个零宽度(不匹配任何字符)断言,检查即将到来的字符。当与懒惰的操作符结合时,它可能是一个很好的方式分手。

答案 1 :(得分:0)

如果我理解正确,你想从每次改变中抓住时间,对吧?要做到这一点,你可以这样改变你的表达方式:

'/PRICE CHANGE\s*(.*?)(\d+:\d+:\d+)/i'

可能i修饰符并非完全必要。