bma*_*man 3 php regex sqlite pdo preg-match
嗨,我想匹配一个字符串:
"\par hello \par world"
反对我的正则表达式 - > \\par
但是,我得到了一个 Compilation failed: unknown property name after \P or \p
我相信我的正则表达式规则被视为unicode字符属性.如何逃避它并按原样运行模式?
我将它包含在PDO函数中.
function sqlite_regExp($sql,$db)
{
if($db->sqliteCreateFunction("regexp", "preg_match", 2) === FALSE) exit("Failed creating function!");
if($res = $db->query($sql)->fetchAll()){ return $res; }
else return false;
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼函数
sqlite_regExp("SELECT COUNT(*) FROM table WHERE REGEXP('/\\par/',column) ",$db)
Run Code Online (Sandbox Code Playgroud)
你需要3个后退\\\.检查此示例:
$string = "\par hello \par world";
$pattern = '/\\\par/';
preg_match_all($pattern, $string, $matches);
var_dump($matches);
Run Code Online (Sandbox Code Playgroud)
您可以在PHP手册中找到更多信息
你已经更新了问题,我看到你没有使用preg_match你正在使用SQL REGEXP函数.但是,SQL函数也应该可以使用\\\.