Search code examples
phpregexstringpreg-matchpcre

regexp to find number between characters


I have a string with the following pattern:

......id\":\"1122575828\",\"raw_id\":1122575828,\"query\".... 

I want to extract the number between raw_id\": and ',' as in raw_id\":(the number),

What should be the right combination in Regexp for PCRE (PHP)?

Thanks in advance.


Solution

  • Use the following regexp pattern with preg_match function:

    $str = "......id\":\"1122575828\",\"raw_id\":1122575828,\"query\"....";
    preg_match('/"raw_id":([^,]+?),/', $str, $matches);
    
    $number = $matches[1];  // 1122575828