Results 1 to 3 of 3

Thread: Preg_match help

  1. #1
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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!
    Last edited by jmace; 10-27-2010 at 05:46 PM. Reason: typo

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •