gpt4 book ai didi

php - Preg_match_all() - 正则表达式太大

转载 作者:行者123 更新时间:2023-11-29 09:26:17 26 4
gpt4 key购买 nike

我该如何改进以下preg_match_all模式,所以我没有这个警告:

preg_match_all(): Compilation failed: regular expression is too large at offset 32036

    $sql = "SELECT skills FROM weighted_skills_industry 
WHERE industry = 'Engineering' ORDER by LENGTH(skills) DESC LIMIT 3000";

$result = $con->query($sql);
while($row = $result->fetch_assoc()) {

$skill[] = $row['skills'];

}
$pattern = '~(?<![\w-])(?:' . implode('|', array_map(function($i) { return preg_quote($i, '~'); }, $skill)) . ')(?![\w-])~i';

if (preg_match_all($pattern, $text, $matchWords)) {

//write something
}

最佳答案

我可能会使用以下查询:

SELECT skills
FROM weighted_skills_industry
WHERE
industry = 'Engineering' AND
skills REGEXP CONCAT('[[:<:]]', ?, '[[:>:]]')
ORDER BY
LENGTH(skills) DESC
LIMIT 3000;

对于 ? 占位符,您可以绑定(bind) PHP 代码中的 $text 变量。上述逻辑将返回文本中可以找到的所有技能。

关于php - Preg_match_all() - 正则表达式太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59552096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com