php - Get all matches in a regular expression -


i have url:

uploads/offers/picture/_ytoxontzojc6im9wdglvbnmio3m6mty6inpvb21dcm9wldi4ms_/_wymdaio30=_/518edc82d94b0-201341717250_descuen_a06d000000fkvwpiak_1_1.jpg  

and need /_(.*)_/ parts, preg_match_all expression seems bad formed:

preg_match_all('#/_([^_/]+)_/#', $url, $params); 

returns

array (     [0] => array         (             [0] => /_ytoxontzojc6im9wdglvbnmio3m6mty6inpvb21dcm9wldi4ms_/         )     [1] => array         (             [0] => ytoxontzojc6im9wdglvbnmio3m6mty6inpvb21dcm9wldi4ms         ) ) 

and need

array (     [0] => array         (             [0] => /_ytoxontzojc6im9wdglvbnmio3m6mty6inpvb21dcm9wldi4ms_/             [1] => /_wymdaio30=_/         )     [1] => array         (             [0] => ytoxontzojc6im9wdglvbnmio3m6mty6inpvb21dcm9wldi4ms             [1] => wymdaio30=         ) ) 

some problem common string parts in expression?

one problem current solution matches / @ end of expression explosion pill's answer says; using positive lookahead solve problem.

another possible issue [^_/] part may end breaking regex if input contains underscores part of matches want capture.

to solve both issues @ once:

~/_(.+?)_(?=/)~ 

this seems me closer after: "whenever see sequence /_ start capturing input until come across sequence _/". lone underscores inside input not break this.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -