You don’t need a regular expression for that. I would do
string = "What $noun$ is $verb$?"
print string.replace("$noun$", "the heck")
Only use regular expressions when needed. It’s generally slower.
More Related Contents:
- Remove specific characters from a string in Python
- How to search and replace text in a file?
- Speed up millions of regex replacements in Python 3
- Best way to replace multiple characters in a string?
- How to use string.replace() in python 3.x
- String replace doesn’t appear to be working
- How to input a regex in string.replace?
- python replace single backslash with double backslash
- replacing text in a file with Python
- Removing a list of characters in string
- Replace nth occurrence of substring in string
- Keeping only certain characters in a string using Python?
- Python Replace \\ with \ [duplicate]
- Replace first occurrence only of a string?
- Mass string replace in python?
- Replace special characters in a string in Python
- pandas: replace string with another string
- How to remove all characters before a specific character in Python?
- Adding backslashes without escaping [duplicate]
- Mutable and Immutable Strings in python
- Python replace function [replace once]
- How to find all occurrences of a substring?
- How to convert string to binary?
- ‘str’ object does not support item assignment
- How to remove all characters after a specific character in python?
- How to create a numpy array of arbitrary length strings?
- How to write very long string that conforms with PEP8 and prevent E501
- Inserting the same value multiple times when formatting a string
- How to create raw string from string variable in python?
- How does str.startswith really work?