使用PHP preg_quote时正则表达式不能很好地显示

Hi Im trying to concatinate a string before converting that string into regex in PHP, but the problem is it's not displaying as expected. I've been searching using google and found out about preg_quote, problem is it's not working well.

Here is my example:

$mystring = "banana"; // put this to a variable assume this value is dynamic
$regex_str = "/^"$mystring"\-[a-z0-9]\-[a-z0-9]$/"; 
//Im expecting expecting /^banana\-[a-z0-9]\-[a-z0-9]$/
$regex = preg_quote($regex_str);

but what I am getting is:

/\^banana\\\-\[a\-z0\-9\]\\\-\[a\-z0\-9\]\$/

and always returning the wrong value.

Call preg_quote() on the string you're adding before you add it into the regex:

$mystring = "banana";
$regex_str = "/^" . preg_quote($mystring, "/") . "\-[a-z0-9]\-[a-z0-9]$/";