3 回答

TA贡献1865条经验 获得超7个赞
你应该考虑使用一些 NLP 包将文本拆分成句子。然后使用
^This\s+\S+\s+\S+\s+on\b
它匹配一个以 wth 开头的字符串This
,然后有两个包含任何非空白字符的单词,然后是单词on
。
见证明
解释
NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
This 'This'
--------------------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\S+ non-whitespace (all but \n, \r, \t, \f,
and " ") (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\S+ non-whitespace (all but \n, \r, \t, \f,
and " ") (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
on 'on'
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char

TA贡献1815条经验 获得超10个赞
最基本的正则表达式是
/\bThis\s+\w+\s+\w+\s+on\b/
这将匹配没有捕获。也许您认为的“单词”字符可能与正则表达式引擎认为的单词字符不同。

TA贡献1775条经验 获得超8个赞
(?:^|[.;!?]\s+)(\bThis\W*?(\b\w+\b)\W*?(\b\w+\b)\W*on\b)
这样的事情会起作用吗?据我了解,您希望句子有四个词,以“This”开头,以“on”结尾。
添加回答
举报