ok so after some time i can do some simple reg exp but this one is confusing me. I currently am testing my reg exp on regexpal.com but php wants to work differently

this is what im using

preg_match_all('/{(\w+)(([:]\w+)*)}/', $page_content, $matches, PREG_SET_ORDER);
		
		foreach($matches as $match) {
			$src = $match[1];
			
			
			echo ($match[0])?$match[0]."/":'';
			echo ($match[1])?$match[1]."/":'';
			echo ($match[2])?$match[2]."/":'';
			echo ($match[3])?$match[3]."/":'';
			echo ($match[4])?$match[4]."/":'';
			echo '<br />';
			
			}

i am trying to match
{asda:asdasad:asdasd:asd3ea:666}

but im getting
/asda/:asdasad:asdasd:asd3ea:666/:666/

need to get
asda/:asdasad/:asdasd/:asd3ea/:666

i need to be to put these items into an array which i can do only if i can get the items by themselves.

this is what i have tried
{(\w+)([:]\w+)?}
{(\w+)(([:]\w+)+)?}
{(\w+)([:]\w+)+}
{(\w+)([:]\w+)([:]\w+)([:]\w+)([:]\w+)}

the last one works only if i have the 5 different items. but not all the items are going to have 5 items. they range from the first item up to the 5th.

i just dont understand why this works on the example of the website but in php it hates me.

thanks in advance

{(\w+)(:\w+)+}

What do you need to put in an array ? Only the words ? Can't you use explode() ?

{(\w+)(:\w+)+}

What do you need to put in an array ? Only the words ? Can't you use explode() ?

The expression you gave me didnt work either.

What i am doing is grabbing all the "template items" within content like
{asda:asdasad:asdasd:asd3ea:666}
Then i need to take each item (in this case things after :) and put them into an array for later use. then put that into a bigger array with the arrays of other template items
ex:

array(
array(0=>asda, 1=>:asdasad, 2=>:asdasd, 3=>asd3ea, 4=>:666)
array(0=>button, 1=>:left)
);

But i need it to read all the template items correctly whether it have 1 or 5 different items within itself.

the expression that you gave me only outputs

Array ( [0] => Array ( [0] => {asda:asdasad:asdasd:asd3ea:666} [1] => asda [2] => :666 ) )

i need

array(0=>asda, 1=>:asdasad, 2=>:asdasd, 3=>asd3ea, 4=>:666)

I think you should just remove the brackets from the returned value 0, and then use explode() that value using the colon into an array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.