Mike Johnson Jr Mike Johnson Jr - 1 year ago 79
Python Question

In python how can I add a special case to a regex function?

Say for example I want to remove the following strings from a string:

remove = ['\\u266a','\\n']

And I have regex like this:

string = re.sub('[^A-Za-z0-9]+', '', string)

How can I add "remove" to my regex function?

Answer Source

you can always remove them before doing the regex like so:

remove = ['\\u266a','\\n']

for substr in remove:
    string.replace(substr, '')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download