亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

每個句子的前四個單詞,但必須以單詞 X 開頭,以單詞 Y 結尾

每個句子的前四個單詞,但必須以單詞 X 開頭,以單詞 Y 結尾

慕娘9325324 2022-12-29 16:05:16
我想過濾每句話的前四個詞,第一個詞是“This”,最后一個詞是“on”。我一直在嘗試觀看 YouTube 教程,但我所能做的就是:([A-Z](?:[^\s.!?]+(?:\s|\n)){0,4}(?:[^\s.!?]+)?)現在,這里有一個例子:這個 [perception resids] on...
查看完整描述

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


查看完整回答
反對 回復 2022-12-29
?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

最基本的正則表達式是

/\bThis\s+\w+\s+\w+\s+on\b/

這將匹配沒有捕獲。也許您認為的“單詞”字符可能與正則表達式引擎認為的單詞字符不同。


查看完整回答
反對 回復 2022-12-29
?
www說

TA貢獻1775條經驗 獲得超8個贊

(?:^|[.;!?]\s+)(\bThis\W*?(\b\w+\b)\W*?(\b\w+\b)\W*on\b)

這樣的事情會起作用嗎?據我了解,您希望句子有四個詞,以“This”開頭,以“on”結尾。


查看完整回答
反對 回復 2022-12-29
  • 3 回答
  • 0 關注
  • 133 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號