在PHP中使用{}的正则表达式:在括号中扫描世界并放入数组

时间:2014-12-01 07:05:04

标签: php regex

我的格式如下:

" Hello {name} , I have receive from {email}, from {date} . THanks"

我想扫描并获取{}中的所有世界,例如{name}{email}等等,并将它们放在一个格式为array("{name}","{email}","{date}")的数组中。请帮我使用preg_match函数(?)

1 个答案:

答案 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);