php - 自然语言处理的正则表达式 "does not contain"模式问题

标签 php regex algorithm artificial-intelligence pcre

链接到 regex101

I am implementing a simple NLP algo. I have already implemented the solution looping over the raw string to assist the regex, but now I want to see if I can do it in pure regex.


我不知道如何让“构建”小组尊重 future 的负面看法。我正在 try catch [“自然语言处理”算法] 任何帮助将不胜感激,谢谢😀
$subject_string = <<<'subject_string'
Projects I've built & Plan to build. HackMatch.io (May 2020 onward), 
As of October 2020, I intend to start implementing "Natural Language Processing" algorithms 
in PHP when I have time. I'll then use PHP to upload the results to big data tech (e.g. BigQuery) 
to create some data visualizations.
subject_string;

$pattern = <<<'pattern'
/\b(?'verb'build|make|implementing)
(?'build'.+?(?!build|make|implementing)) 
(?=\bin\b|\bon\b)
(?:build|make|implementing)??/ix
pattern;

preg_match_all($pattern, $subject_string, $matches)

最佳答案

您可以使用

/\b(?'verb'build|make|implementing)\s*
(?'build'(?:(?!(?&verb)).)*?) 
(?=\s*\b(?:in|on)\b)/ixs
regex demo . 详情 :
  • \b - 一个词边界
  • (?'verb'build|make|implementing) - 组“动词”:括号内的词之一
  • \s* - 零个或更多空格
  • (?'build'(?:(?!(?&verb)).)*?) - 组“build”:任何字符,零次或多次出现,但尽可能少,不会开始“动词”组中定义的任何字符序列
  • \s* - 零个或更多空格
  • (?=\b(?:in|on)\b) - 与紧跟在整个单词后面的位置匹配的正向前瞻 inon .
  • 关于php - 自然语言处理的正则表达式 "does not contain"模式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64402133/

    相关文章:

    ruby-on-rails - 如何使用正则表达式模式从 URL 中提取参数

    algorithm - 如何计算第三个值的两个值范围之间的百分比

    java - 二维数组中上升和下降的最小量

    php - 使用 php 将复选框输入插入 postgresql

    php - 对于每个循环和 fancybox

    PHP mail() 奇怪的附加信息自动发送

    java - 如何找到模式的后半部分?

    python - 具有多个组的正则表达式?

    algorithm - 从一个点找到最近的圆

    php - 从单个数组创建多维数组