I have to search for a pattern either inside the content of a variable or inside a data file. Below is the code I have so far:
import re
UserSpecifiedPattern = "segfault"
# find every instance of a user specified pattern
pattern = re.compile( rb'(\.\W+)?([^.]?segfault[^.]*?\.)',
re.DOTALL | re.IGNORECASE | re.MULTILINE )
My problem is, how does one specify a variable to "re.compile". Meaning, I'm storing the actual pattern to be searched into a variable. And I'm then giving that variable to re.compile. The below is what I presume should work, but it isn't:
import re
UserSpecifiedPattern = "segfault"
# find every instance of a user specified pattern
pattern = re.compile( rb'(\.\W+)?([^.]?UserSpecifiedPattern[^.]*?\.)',
re.DOTALL | re.IGNORECASE | re.MULTILINE )
I'm guessing this should be it?
import re
UserSpecifiedPattern = "segfault"
# find every instance of a user specified pattern
pattern = re.compile( rb'(\.\W+)?([^.]?{UserSpecifiedPattern}[^.]*?\.)',
re.DOTALL | re.IGNORECASE | re.MULTILINE )