Php 为什么我的正则表达式拒绝撇号?

Php 为什么我的正则表达式拒绝撇号?,php,regex,apostrophe,Php,Regex,Apostrophe,我正在制作一个正则表达式,它应该匹配所有类似的内容:[[第一个示例]]或[[我是一个示例]] 不幸的是,由于撇号,它与[[我是一个示例]]不匹配 这是: preg_replace_callback('/\[\[([^?"`*%#\\\\:<>]+)\]\]/iU', ...) preg\u replace\u回调('/\[\[([^?”`*%\\\\\\:]+)\]\]\]\]/iU',…) 简单的撇号(')是允许的,所以我真的不明白为什么它不起作用 有什么想法吗 编辑:下面是我

我正在制作一个正则表达式,它应该匹配所有类似的内容:
[[第一个示例]]
[[我是一个示例]]

不幸的是,由于撇号,它与
[[我是一个示例]]
不匹配

这是:

preg_replace_callback('/\[\[([^?"`*%#\\\\:<>]+)\]\]/iU', ...)
preg\u replace\u回调('/\[\[([^?”`*%\\\\\\:]+)\]\]\]\]/iU',…)
简单的撇号(')是允许的,所以我真的不明白为什么它不起作用

有什么想法吗

编辑:下面是我使用这个正则表达式之前发生的事情

// This match something [[[like this]]]
$contents = preg_replace_callback('/\[\[\[(.+)\]\]\]/isU',function($matches) {
    return '<blockquote>'.$matches[1].'</blockquote>';
}, $contents);

// This match something [[like that]] but doesn't work with apostrophe/quote when
// the first preg_replace_callback has done his job
$contents = preg_replace_callback('/\[\[([^?"`*%#\\\\:<>]+)\]\]/iU', ..., $contents);
//这个匹配某个东西[[[像这样]]]
$contents=preg\u replace\u回调('/\[\[\[(.+)\]\]\]\]\]/isU',函数($matches){
返回“”。$matches[1]”;
}(港币),;
//这与某事物[[像那样]]匹配,但与撇号/引号不匹配
//第一个preg_replace_回调完成了他的工作
$contents=preg\u replace\u回调('/\[\[([^?”`*%\\\\\:]+)\]\]\]\]/iU',…,$contents);
试试这个:

$string = '[[First example]]';
$pattern = '/\[\[(.*?)\]\]/';
preg_match ( $pattern, $string, $matchs );
var_dump ( $matchs );

您可以使用此正则表达式:

\[\[.*?]]

Php代码

$re = '/\[\[.*?]]/'; 
$str = "not match this but [[Match this example]] and not this"; 

preg_match_all($re, $str, $matches);
顺便说一句,如果要捕获括号内的内容,必须使用捕获组:

\[\[(.*?)]]

它确实有效。请尝试使用
preg\u match\u all
@vks我正在使用
preg\u replace\u callback
(更正)
在那里。这应该是一句话吗?这是一个勾号,,而不是一个引号,——两种不同的动物,尽管这不是问题所在,但它可以正常工作。回调的作用是什么<代码>$string='[[我是一个例子]]';preg\u match('/\[\[([^?”`*%\\\:]+)\]\]\]/iU',$string,$matches);print\r($matches);@Fred ii-这是一个不允许的记号,如下字符:?“*%\\:<>我们能先试试看他们的代码为什么失败,而不是“试试这个”吗?也许再加一个解释就好了。@Fred ii-我在我的问题上加了一些细节