Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
1 つの単語を含むが繰り返されていない行を選択する方法。文字列 word1 を探しているとしましょう
テキスト word1 テキスト #match
text word1 text word1 #not match 、原因 word1 が繰り返されています。
word1 word1 word1 # 不一致、繰り返し
word1 #一致
text text text text word1 # 一致
これらの行に一致する正規表現を開発する方法を誰かが教えてくれますか??
これを試して:
(\b\w+\b)(?!.*\1)
キャプチャされた単語への後方参照への否定的な先読みを使用します
あなたも試すことができます
^(?!.*(\bword1\b).*\b\1\b).*\bword1\b.*$
hereは、任意の単語に一致させたい場合word1に置き換えることができます..\w+
word1
\w+
multilineオプションで使う
multiline