regex - Extracting substrings ending with "mp4" -


i have following input:

string='get........ref=mp4;get........ref=flv;get........ref=mp4;' 

it has 3 segments. need extract segments ending mp4;.

ie.

get........ref=mp4 get........ref=mp4 

the current result match get........ref=mp4 , get........ref=flv;get........ref=mp4;.

my regular express: get(.*?)mp4

i don't need long match containing flv inside, , regex not work: get(.*?)(?!:flv)mp4

i don't know how solve , appreciated.

you can explode semi-colon separated list , use preg_grep elements end mp4:

$string='get........ref=mp4;get........ref=flv;get........ref=mp4;'; $res = explode(";", $string); $res = preg_grep('/mp4$/i', $res); print_r($res); 

see ideone demo

if there no semi-colons, glued:

// no semi_colons $str='get........ref=mp4get........ref=flvget........ref=mp4'; preg_match_all('/get\b(?:(?!get\b).)*mp4(?=$|get\b)/', $str, $res); print_r($res); 

see another ideone demo


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -