There are many answers to a similar type of question to mine, but I'm not sure why this isn't working.
I've got a very simple example of two strings, where I am checking if one is contained in another (with an exact match).
For example, suppose I've got the following:
import re
text = "random/path/"
search = "test/random/path/path_with_brackets[3]/another_path"
if re.search(r"\b{}\b".format(text), search, re.IGNORECASE) is not None:
print("text is contained in search")
else:
print("text not contained in search")
As expected, the above code returns:
text is contained in search
since an exact match of "random/path/" is found in "test/random/path/path_with_brackets[3]/another_path"
However, if I add an extra path (that contains brackets) to the text, such as:
import re
text = "random/path/path_with_brackets[3]"
search = "test/random/path/path_with_brackets[3]/another_path"
if re.search(r"\b{}\b".format(text), search, re.IGNORECASE) is not None:
print("text is contained in search")
else:
print("text not contained in search")
the text is not found in search, even though it exists. The result is:
text not contained in search
What am I doing wrong in the second example? Does the fact that "text" have brackets change anything?