Preg_match return all parts in array?

You need preg_match_all preg_match_all( '~(/\w+)~', $str, $matches ) in your situation you can use explode too.

You need preg_match_all preg_match_all( '~(/\w+)~', $str, $matches ); in your situation you can use explode too.

Sorry, I think I didn't make my question clear enough. I updated it with one more example. And explode isnt really a solution here, because I can also have string like this: /1:2:3:4 etc, so i'm generating my regular expression in php depending on some parameters I get.

– Denis Nov 3 '10 at 22:17 my code still works =) – Galen Nov 3 '10 at 22:44 :) yeah, but that's not really the solution i'm searching for. Now I doubt it exists :) – Denis Nov 3 '10 at 23:09 1 well it gives the exact result you posted that you want, so you should update your question. – Galen Nov 3 '10 at 23:23 Your code works in one type of situation and shows the problem with testing.

You also need to check the counter-examples as to be able to say it works right. – Peter Stuifzand Nov 3 '107 at 10:35.

Prints: Array ( 0 => /a 1 => /b 2 => /1 3 => /2 4 => /3 5 => /4 ).

– Denis Nov 3 '10 at 22:38 1 @Denis, no you can't. Why does this solution not work for you? – eyelidlessness Nov 4 '10 at 18:41.

(?R))%" This works my matching (/\w+) subexpressions in turn. Therfore the match for "/a/b/1/2/3/4" Would be: Array ( 0 => Array ( 0 => /a 1 => /b 2 => /1 3 => /2 4 => /3 5 => /4 ) ... However your later examples complicate things. A simple 0 or more match will only return the last (greedy) or first (ungreedy) match - not all submatches.

Preg_match_all won't be able to handle your dynamic expression. You will have to clarify what you're trying to achieve in more detail before a suitable solution can be provided.

What i'm trying to archive: i've got a string, and I want to test it with regexp, and split into parts. I want to do it all in one preg_match (or preg_match_all), and I need splited parts to be in same order they apeard in original string. I'm generating regular expressions on some conditions i'm give, e.g. : (/)(-)(/)*, the last one repeats zero or more times (it also can be in the middle of the string and repeat from 2 to 5 times, etc).

I do can test the string with preg_match, and then manually split it, but I was searching for a nicer way to do it. – Denis Nov 3 '10 at 23:06 I just thought it's as simple as add some character to my regulat expression :) – Denis Nov 3 '10 at 23:08.

This works my matching (/\w+) subexpressions in turn. However your later examples complicate things. A simple 0 or more match will only return the last (greedy) or first (ungreedy) match - not all submatches.

Preg_match_all won't be able to handle your dynamic expression. You will have to clarify what you're trying to achieve in more detail before a suitable solution can be provided.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions