- Ctrl + H
- Localizar:
(?:^(?<!#).*\K|(<?!"))\bhat\b(?!")
- Substituir:
llama
- verificar expressão regular
- marque a palavra inteira
- check Wrap
- Substituir todos
Explicação:
(?:
^ : 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
Dado:
# Where did my hat go?
hat = 0
chat = 0
print(hat)
print("hat")
print(chat)
Resultado para o exemplo dado:
# Where did my hat go?
llama = 0
chat = 0
print(llama)
print("hat")
print(chat)
Antes: