In the below example I want to only return True for the last string in the Series. This means I have to add a conditional escaping any plus symbols so that they actually get searched and it doesn't take on its special regex function.
import pandas as pd
testseries=pd.Series(["product a basic","product a","product a+","product b basic","product b","product b+"])
#this string will be unknown in practice
searchstring="b+"
# Necessary cleaning conditional
if "+" in searchstring:
searchstring = searchstring.replace("+","\\+")
#Search is actually performed
print(searchstring)
testseries.str.contains(searchstring)
In practice I am not going to know what searchstring is going to be. Is there a function or different approach for ensuring that any characters that need to be escaped are correctly escaped?
I don't want to keep having to create a ever increasing chain of conditionals that clean the searchstring or is this inevitable?