Can anyone help me understand why this works…
z = re.findall(r'(foobar)', string)
But this doesn’t?
regexStr = "r'(foobar)'"
z = re.findall(regexStr, string)
I’ve printed regexStr and determined that it’s output is IDENTICAL to r'(foobar)’.
Can someone pls help? I’ve also tried escaping the apostrophes too.
JD
A solution to your problem is
where searchString will replace %s
In Python it is often better to use this construct than regular concatenation. (meaning str1 + str2 + … )
Especially as you don’t have to care about converting ints doubles and so on.
More on the subject here: 3.5. Formatting Strings
The r should not be part of the string, it only tells the python interpreter what kind of string it is: