我想拿出那个创建了一个数组,看起来像下面的一个正则表达式,从以下字符串正则表达式的preg_match | preg_match_all在PHP
$str = 'Hello world [something here]{optional}{optional}{optional}{n possibilities of this}';
到目前为止,我有/^(\*{0,3})(.+)\[(.*)\]((?:{[a-z ]+})?)$/
Array
(
[0] => Array
(
[0] => Hello world [something here]{optional}{optional}{optional}{n possibilities of this}
[1] =>
[2] => Hello world
[3] => something here
[4] => {optional}
[5] => {optional}
[6] => {optional}
[7] => ...
[8] => ...
[9] => {n of this}
)
)
这会是一个很好的方法吗?谢谢
它是如何重要得到结果数组精确的问题?此外,是你想要匹配的“真实”字符串还是一个简单的例子? – salathe 2010-05-03 20:50:59