Destramic Posted May 15, 2016 Share Posted May 15, 2016 hey guys, i'm trying to get back in to the swing of things after a lot of time out from programming, and i'm struggling with this simple regex pattern if i could get some help please. i've decided to go over some of my code and try and re-write things better....starting with my framework. here is my pattern: /^\/?(i|s)?:+([A-Za-z0-9_-])$/ what im trying to do is match: news/i:news_id - returning strings i (if there) and news_id as the string is uri it could contain a forward slash at the beginning. if (preg_match_all('/\/?(i|s)?:+([A-Za-z0-9_-])/', 'my-page/i:foo/:bar', $fixed_parameters)) { print_r($fixed_parameters); } result: Array ( [0] => Array ( [0] => i:f [1] => /:b ) [1] => Array ( [0] => i [1] => ) [2] => Array ( [0] => f [1] => b ) ) idealy what i'd like is a result like this: Array ( [0] => Array ( [0] => i [1] => foo ) [1] => Array ( [0] => [1] => bar ) ) thanks guys Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted May 15, 2016 Solution Share Posted May 15, 2016 You aren't repeating that character set at the end. As for the format, [0] will always be the full match. Best you can get is "i" as [1] and the identifier as [2] by using what you have now with the PREG_SET_ORDER flag. 1 Quote Link to comment Share on other sites More sharing options...
Destramic Posted May 17, 2016 Author Share Posted May 17, 2016 brilliant thank you very much requinix. i used this pattern which seems to work fine /(i|s)+:+([A-Za-z0-9_-]\w*)/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.