链接到 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)
- 与紧跟在整个单词后面的位置匹配的正向前瞻 in
或 on
. 关于php - 自然语言处理的正则表达式 "does not contain"模式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64402133/