Search code examples
phpregexwordpresspreg-match

Find value from a string


I have a string like below

include="3524,3525,3523"][/vc_column_inner][/vc_row_inner][/‌​vc_column][/vc_row][‌​vc_row][vc_column][v‌​c_video link="youtube.com/watch?v=pkBBzH"][/vc_column][/vc_row] 

I just want to extract integer values from string 3524,3525,3523. The number of numeric values can increase I am using the below code

$matches = array();
$content1 = preg_match('/include="(.*)"/',$content1,$imagesmatches);
print_r($matches);

This gets the values and everything else i just want numbers. I know i am using wildcard but i need a expression to just extract numbers from it.


Solution

  • Based on edited question you can use:

    preg_match('/include="\K\d+(?:,\d+)*/', $content, $matches);
    
    print_r($matches[0]);
    

    RegEx Demo