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

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

正則表達式 lookaround 的一個問題。

正則表達式 lookaround 的一個問題。

心有法竹 2018-08-22 10:09:01
問題是關于 Positive 和 Negative LookAhead 的一個模式:匹配的文本為 quite\nqaiet首先第一個模式: q(?=u) 毫無疑問,第一個q 會被匹配到,第二個模式 q(?!u) 毫無疑問,第二個q 會被匹配到接下來疑問來了,請問q(?=u)i 這個模式能匹配到怎么樣的文本?
查看完整描述

1 回答

?
猛跑小豬

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

可以匹配 qii 這個文本,關于 為什么無法匹配到quite 的原因是:
文本 quite
模式 q(?=u)i

解釋如下:

q matches q and u matches u. Again, the match from the lookahead must be discarded, so the engine steps back from i in the string to u. The lookahead was successful, so the engine continues with i. But i cannot match u.

中文解釋就是,模式中的q匹配了文本中的q,模式中的u匹配了文本中的u,由于這個是 lookahead 模式,所以,下一個匹配還是從文本中的u開始,然而 文本中的 u 并不匹配 模式中的i,所以這不會匹配。

PS:The difference is that lookaround actually matches characters, but then gives up the match, returning only the result: match or no match.


查看完整回答
反對 回復 2018-08-26
  • 1 回答
  • 0 關注
  • 750 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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