It should work fine everywhere if remove that
The error happens before comments part.
Tested VS Code,PyScripter,cmder,IDLE okay.
\0
and have normal characters as replace.The error happens before comments part.
Tested VS Code,PyScripter,cmder,IDLE okay.
import re string1 = 'Agent Cheesecake was a double agent.' agent_names_regex = re.compile(r'Agent (\w)\w*') mo_0 = agent_names_regex.sub(r'***', string1) print(f"This is string1 '{string1}' with *** after censorship: {mo_0}") ##Output: ## # This is string1 'Agent Cheesecake was a double agent.' with *** after censorship: *** was a double agent. ## ##>>>