Page 1 of 1

Regex help

Posted: Thu Jan 23, 2014 5:09 pm
by Minouch
Hi;
I need to grab any the format ten numbers then a dot then jpg or png inside the {image}{/image} tag, for example :

1. {image}1390324469.jpg{/image} should return 1390324469.jpg without spaces
2. {image} 1390324469.jpg {/image} should return 1390324469.jpg without spaces
3. {image}unicode or non numbners characters1390324469.jpgunicode or non numbers characters{/image} should return 1390324469.jpg without spaces

This one "#{image}(.*?){\/image}#i", does only work in the first case and doesn't work in the second and third cases.
Thank you.

Re: Regex help

Posted: Thu Jan 23, 2014 5:22 pm
by Celauran

Code: Select all

php > $haystack = '{image}abcdefg1390324469.jpgabcdefg{/image}';
php > preg_match('/\{image\}.*?(\d{10}\.(jpg|png)).*?\{\/image\}/', $haystack, $matches);
php > print_r($matches);
Array
(
    [0] => {image}abcdefg1390324469.jpgabcdefg{/image}
    [1] => 1390324469.jpg
    [2] => jpg
)
php >

Re: Regex help

Posted: Thu Jan 23, 2014 5:41 pm
by Minouch
Quick and wright answer, this one work,
"#{image}.*?(\d{10}\.(jpg|png)).*?{\/image}#i"

Thank you