trying to seperate a list of values with regular expressions
Posted: Thu Jan 25, 2007 5:24 am
Hello,
I'm trying to build a method on my mysql object that will allow me to pass in a associated array of columns and values. I'm at the part where a value might have a few items to it. I need to clean each one and then insert it.
Here is an example of what I mean
passed in value:
I want to be able to split the contents of METHOD_1 into its three parts
I can't seem to create the regular expression that will allow it to ignore commas inside parentheses.
This is what I have so far
This is what I get
Can someone please help me create the right regular expression to make this work?
I'm trying to build a method on my mysql object that will allow me to pass in a associated array of columns and values. I'm at the part where a value might have a few items to it. I need to clean each one and then insert it.
Here is an example of what I mean
passed in value:
Code: Select all
METHOD_1('string',number,METHOD_2(number,'string'))Code: Select all
'string'
number
METHOD_2(number,'string')This is what I have so far
Code: Select all
<?
$string = "'this where it gets sticky', something('here is', 7897,'this is a test') , any('here is another')";
$pattern = "/([a-zA-Z_]*[\(]?[\)]?)(.*?)\\1(?:,|$)/";
preg_match_all($pattern,$string,$matches);
echo $string."<br/>";
echo "<pre>";
print_r($matches);
echo "</pre>";
?>Code: Select all
Array
(
[0] => Array
(
[0] => 'this where it gets sticky',
[1] => something('here is',
[2] => 7897,
[3] => 'this is a test') ,
[4] => any('here is another')
[5] =>
)
[1] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
)
[2] => Array
(
[0] => 'this where it gets sticky'
[1] => something('here is'
[2] => 7897
[3] => 'this is a test')
[4] => any('here is another')
[5] =>
)
)