2012-01-07 78 views
0

工作,我有這樣的數據:正則表達式表達不會與preg_match_all

49780|Truck|2010|FORD|F-250 SUPER DUTY PICKUP|CABELAS|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-250 SUPER DUTY PICKUP|FX4|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-250 SUPER DUTY PICKUP|FX4|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-250 SUPER DUTY PICKUP|HARLEY-DAVIDSON EDITION|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-250 SUPER DUTY PICKUP|KING RANCH|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-250 SUPER DUTY PICKUP|LARIAT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-250 SUPER DUTY PICKUP|LARIAT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-250 SUPER DUTY PICKUP|LARIAT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-250 SUPER DUTY PICKUP|XL|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-250 SUPER DUTY PICKUP|XL|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-250 SUPER DUTY PICKUP|XL|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-250 SUPER DUTY PICKUP|XLT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-250 SUPER DUTY PICKUP|XLT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-250 SUPER DUTY PICKUP|XLT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-350 SUPER DUTY PICKUP|CABELAS|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-350 SUPER DUTY PICKUP|FX4|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-350 SUPER DUTY PICKUP|FX4|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-350 SUPER DUTY PICKUP|HARLEY-DAVIDSON EDITION|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-350 SUPER DUTY PICKUP|KING RANCH|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-350 SUPER DUTY PICKUP|LARIAT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-350 SUPER DUTY PICKUP|LARIAT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-350 SUPER DUTY PICKUP|LARIAT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-350 SUPER DUTY PICKUP|XL|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-350 SUPER DUTY PICKUP|XL|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-350 SUPER DUTY PICKUP|XL|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2008|FORD|F-350 SUPER DUTY PICKUP|XLT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2009|FORD|F-350 SUPER DUTY PICKUP|XLT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 
49780|Truck|2010|FORD|F-350 SUPER DUTY PICKUP|XLT|6.4L DIESEL V8|||Crew Cab w/81.8 in./6 ft. 9.8 in. Bed|Extended Cab w/81.8 in./6 ft. 9.8 in. Bed 

我寫了使用RegExr這個正則表達式。它捕捉到第5列(由分隔|),如果該行是匹配:

.*\|.*\|2010\|ford\|(.*)\|.*\|.*\|.*\|.*\|.*\|.* 

當我運行就可以了preg_match_all,我得到這個錯誤:

preg_match_all() [<a href='function.preg-match-all'>function.preg-match-all</a>]: Unknown modifier '*' 
+0

http://ideone.com/oxFBk ---您正則表達式的工作沒有錯誤 – zerkms 2012-01-07 21:24:15

+0

我真的很好奇,爲什麼從b第四行數據中的ottom與其餘的語法突出顯示不同。 – Paulpro 2012-01-07 21:30:24

回答

3

請確保您使用delimiters,它看起來像你想有一個case insensitive比賽還有:

$matches = array(); 
preg_match_all('/.*\|.*\|2010\|ford\|(.*)\|.*\|.*\|.*\|.*\|.*\|.*/i', $subject, $matches); 
+0

這很好 - 我接受了答案。這可能是我缺乏理解 - 但它應該返回兩個(F-250 SUPER DUTY PICKUP)時纔會返回一個匹配(F-350 SUPER DUTY PICKUP) – Avisra 2012-01-07 21:33:58