我想匹配一個不以 << 開頭或不以 >> 結尾的單詞(在句子中)。
例句:
Lorem Ipsum It has survived not only five centuries. <<Lorem Ipsum Lorem Ipsum>> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing passages, and more recently with desktop publishing software like Aldus PageMaker including versions of.
在這句話中,只有 2 個“Lorem Ipsum”符合我們的規則(不以 << 開頭或不以 >> 結尾)
我試過這個但不起作用
/(?!<<)(lorem ipsum)(?!>>)/i
如何使它作業?
uj5u.com熱心網友回復:
您(?!<<)在單詞前后都使用了否定前瞻。此外,您還沒有包含全域標志 'g',因此根據您的環境,它可能會在第一次匹配后回傳。嘗試將第一個前瞻更改為后視,并可選擇添加 'g' 標志:
(?<!<<)(lorem ipsum)(?!>>)
或作為 JavaScript RegExp 文字:
/(?<!<<)(lorem ipsum)(?!>>)/gi
在這里試試:https : //regex101.com/r/Pa1b5n/1
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/321111.html
標籤:正则表达式
