regex problem

From: Date: Thu, 13 Mar 2003 15:36:45 +0000
Subject: regex problem
Groups: php.general 
Request: Send a blank email to php-general+get-139525@lists.php.net to get a copy of this message
hi, suppose there's a string $string="I like my(hot) coffee with sugar and (milk)(PHP)"; I would like to get an output of all possible combinations of the sentence with the words between brackets: eg. I like my hot coffee with sugar and I like my hot coffee with sugar and milk I like my hot coffee with sugar and milk php I like my coffee with sugar and I like my coffee with sugar and milk php etc.etc. The number of the words between brackets can differ and they can occur everywhere. The most important is that all combinations are returned but the sentence (not between brackets) should be there. I got something like: preg_match("/\((.*?)\)(.*)\((.*?)\)+/",$string,$regresult); but the \((.*?)\) part that matches the things between brackets is fixed. There can be a variable number of these words between brackets. How do i do this? And how could i easily get the combinations? Can i do it all just with preg_match or should i construct the combinations with some additional code? thanks; Simon

« previous php.general (#139525) next »