フル機能のPCRE正規表現を本番サーバー上のMySQLデータベース、つまりキャプチャグループ、パターン修飾子(大文字と小文字を区別しない、複数行)、メタ文字、エスケープシーケンス(\s
、\w
)で確実に有効にして使用する方法はありますか?およびその他のPCREグッズ?
2125 次
3 に答える
4
lib_mysqludf_pregは、パターンマッチングのためにPCRE(perl compatible-regular-expressions)ライブラリへのアクセスを提供するmysql UDF(ユーザー定義関数)のライブラリです。
于 2012-12-29T11:29:20.367 に答える
3
MariaDBに切り替えます。10.0.5以降、MariaDBはPCREhttps://mariadb.com/kb/en/mariadb/pcre/をサポートしています
于 2016-01-23T09:37:58.727 に答える
0
MariaDbとPHPは、まったく同じ方法でPCREを実装していません。
- MariaDBに区切り文字はありません
- オプションはこのように最初に与えられます(?options)
そこで実装しましたhttps://github.com/jclaveau/php-logical-filter/blob/master/src/Rule/RegexpRule.php#L57-L82
/**
* Removes the delimiter and write the options in a MariaDB way.
*
* @param string The pattern written in a PHP PCRE way
* @return string The pattern in a MariaDB syntax
*
* @todo Find more difference between MariaDB and PHP and handle them.
* @see https://mariadb.com/kb/en/library/pcre/
*/
public static function php2mariadbPCRE($php_regexp)
{
$delimiter = substr($php_regexp, 0, 1);
$quoted_delimiter = preg_quote($delimiter, '#');
if (!preg_match("#^$quoted_delimiter(.*)$quoted_delimiter([^$quoted_delimiter]*)$#", $php_regexp, $matches)) {
throw new \InvalidArgumentException(
"The provided PCRE regular expression (with the delimiter '$delimiter') cannot be parsed: "
.var_export($php_regexp, true)
);
}
$pattern = $matches[1];
$options = $matches[2];
return ($options ? "(?$options)" : '') . $pattern;
}
対処すべき違いはおそらくもっとたくさんありますが、少なくとも、これは始まりです:)
いくつか見つけて、ケースを追加してテストしたい場合は、ここで私に連絡してください:https ://github.com/jclaveau/php-logical-filter/issues
于 2018-07-17T13:05:45.427 に答える