我似乎无法得到的正则表达式时,我需要使用他们...PHP的preg_match正则表达式的字符串捕获模式
鉴于这样一个字符串:
$string = 'text here [download="PDC" type="A"] and the text continues [download="PDS" type="B"] and more text yet again, more shotcodes might exist ...';
我需要打印“text here”部分,然后根据变量“PDC”和“A”执行mysql查询,然后打印剩余的字符串...(如果字符串中存在更多[下载],则再次重复) 。
到目前为止,我有以下的正则表达式
$regex = '/(.*?)[download="(.*?)" type="(.*?)"](.*?)/';
preg_match($regex,$string,$res);
print_r($res);
但这只是捕捉了以下内容:
Array ([0] => 111111 [1] => 111111 [2] =>)
我使用的preg_match()...我应该使用preg_match_all()代替?无论如何...正则表达式肯定是错误的...任何帮助?
'['打开字符类和']'完成它。这些具有含义的字符需要在PCRE正则表达式中转义或放入QE块中。 – hakre
对不起。我没跟着你... –
什么是“tipo”? –