我有像这样的字符串
$string ="this is test {username} ,{password@123} and Other {asdfg@#$}"
我想把这个字符串作为数组格式如下
[1] => Array
(
[0] => username
[1] => password@123
[2] => asdfg@#$
)
答案 0 :(得分:0)
(?<={)[^}]+(?=})
试试这个。这应该有效。
$re = "/(?<={)[^}]+(?=})/mi";
$str = "this is test {username} ,{password@123} and Other {asdfg@#\$}";
preg_match_all($re, $str, $matches);
答案 1 :(得分:0)
$re = "/\{(.*?)\}/";
$str = "this is test {username} ,{password@123} and Other {asdfg@#\$}";
preg_match_all($re, $str, $matches);
print_r($matches);
这给你想要的东西