我的格式如下:
" Hello {name} , I have receive from {email}, from {date} . THanks"
我想扫描并获取{}中的所有世界,例如{name}
,{email}
等等,并将它们放在一个格式为array("{name}","{email}","{date}")
的数组中。请帮我使用preg_match函数(?)
答案 0 :(得分:1)
{[^}]+}
试试这个。请参阅regex101上的演示。
http://regex101.com/r/sA8iT4/3
$re = "/{[^}]+}/";
$str = "Hello {name} , I have receive from {email}, from {date}";
preg_match_all($re, $str, $matches);