- Ctrl+H
- Найти:
(?:^(?<!#).*\K|(<?!"))\bhat\b(?!")
- Заменить:
llama
- проверьте регулярное выражение
- проверить целое слово
- проверить Wrap
- Replace all
Объяснение:
(?: ^ : beginning of line (?<!#) : negative lookbehind, zero-length assertion that makes sure we don't have # before .* : 0 or more any character \k : forget all we have seen until this position | : OR (?<!") : negative lookbehind, zero-length assertion that makes sure we don't have " before ) \b : word boundary to not match chat, remove it if you want to match chat also hat : literally \b : word boundary to not match hats, remove it if you want to match hats also (?!") : negative lookahead, zero-length assertion that makes sure we don't have " after
Дано:
# Where did my hat go? hat = 0 chat = 0 print(hat) print("hat") print(chat)
Результат для данного примера:
# Where did my hat go? llama = 0 chat = 0 print(llama) print("hat") print(chat)
До: