I'm pretty new to regex. Say that I have a string like so:
UPDATE table_name SET column = :column WHERE column IN(:column_32, :column_34, :column_347)
And then assume that I have an array:
$arr = array(
'column' => 'Test',
'column_32' => 'Tester',
'column_34' => 'Faux data',
'column_347' => 'Column data'
);
What I want to do is replace the placeholders (:column, :column_32 etc) with their corresponding values in the array. Problem is, str_replace wont cut it as replacing :column with 'Test' will result in :column_32 becoming :Test_32 etc.
So, I've started writing some custom regex. Here's a test script I've been running:
foreach($arr as $k => $v){
var_dump(preg_match_all('(:'.$v.'[^_])', $str, $matches));
}
It matches the correct strings. Problem is, it also returns "," and ")" as a part of the match. Am I overlooking something here?