Php 正则表达式在{}中与匹配

Php 正则表达式在{}中与匹配,php,regex,Php,Regex,我在匹配括号中的所有项目时遇到很多问题 下面是一些代码,我需要匹配项做的是输出如下内容 Array ( [0] => username [1] => id ) 一些代码给你一个想法 $ur = '/account/{username}/{id}'; if(preg_match('', $str, $matches)){ print_r($matches); } 我怎样才能做到这一点?你的问题有点让人困惑。你想从这个字符串中检索用户名和id并将这些值存储在一个数组中吗?我猜它

我在匹配括号中的所有项目时遇到很多问题

下面是一些代码,我需要匹配项做的是输出如下内容

Array ( [0] => username [1] => id )
一些代码给你一个想法

$ur = '/account/{username}/{id}';
if(preg_match('', $str, $matches)){
   print_r($matches);
}

我怎样才能做到这一点?

你的问题有点让人困惑。你想从这个字符串中检索用户名和id并将这些值存储在一个数组中吗?我猜它应该更像/account/vince88/1234我想我需要像斯库齐所说的那样,比如a得到一个值$match='/account/{username}/{id}'和$ur='/account/{username}/{id}',我需要匹配ur。
$ur = '/account/{username}/{id}';
preg_match_all('/\{([a-z]+)\}/',$ur,$m);
echo '<pre>';
var_dump($m[1]);
array(2) {
  [0]=>
  string(8) "username"
  [1]=>
  string(2) "id"
}