-
Preg_match help
Hey! I'm trying to get this PCRE syntax right, but so far I can't get it to work. I have stings like this: (The parts in between the [ and ] are suppose be matched)
Code:
Please provide more data and resubmit. '[merchant_sku]' Merchant value: '[03/31096]' catalog value: '[]' '[manufacturer]' Merchant value: '[]' catalog value: '[Oriental Trading]' '[brand]' Merchant value: '[]' catalog value: '[]' '[item_name]' Merchant value: '[Bamboo Limbo Set]' catalog value: '[Bamboo 6' Foot Limbo Kit]' '[part_number]' Merchant value: '[]' catalog value: '[IN-34/64]'. For details, see http://website.com
Here is my REGEXP:
Code:
"/ '(.*?)' Merchant value: '(.*?)' catalog value: '(.*?)'/i"
It captures everything great, until it gets to the "Bamboo 6' Foot Limbo Kit" where it wants to stop at the 6' instead of the Kit'. I've tried adding something like (:?\. | ) to the end, but that just returns blanks for now obvious reasons. How can I get it past that 6' to where it is suppose to end?
Thanks!
-
The '6 has to be \'6 going into the match, or the string has to be delimited with double quotes ("). Either of which can probably be done. But it would depend upon how the string is getting to the match. You don't show that code. What is it?
-
Thanks for the quick reply.
Sorry I didn't post more code. I guess I could have, but it didn't seem really relevant. The string is being pulled in from an error file. From there, the lines are cut using split(), and then there is a foreach statement to take in each line one at a time. Here is the code, if it helps:
PHP Code:
$location = './errors.txt';
$file = fopen($location,'r');
$contents = fread($file,filesize($location));
fclose($file);
$contents = split("\n",$contents);
$att = array();
$x = 0;
foreach($contents as $content){
$content = split("\t",$content);
if(@isset($content[4])){
if(preg_match("/SKU '(\d+?\/\d+?)' appears to correspond to ASIN/i",$content[4],$match)){
$att[$x]['sku'] = $match[1];
preg_match_all("/ '(.*?)' Merchant value: '(.*?)' catalog value: '(.*?)'/i",$content[4],$match);
print_r($match);
$x++;
}
}else{ continue; }
}
Everything matches perfect, except that it stops in the wrong place.