in reply to Regex with variables

Just swap $test and $targets in the 'if' statement.