Better way to replace expressions in Regex

python
regular_expression

#1

Hi,
I am using following technique to replace expressions in regex :

def parse (x):
    x=re.sub('\?',',',str(x))
    x=re.sub('&',',',str(x))
    x=re.sub('\+',',',str(x))
    x=re.sub('/',',',str(x))
    x=re.sub('/',',',str(x))
    x=re.sub(':',',',str(x))
    x=re.sub(';',',',str(x))
    x=re.sub('\*',',',str(x))
    x=re.sub('%',',',str(x))
    x=re.sub('$',',',str(x))
    return re.split(',',str(x))
skill=skill.apply(parse)

Can somebody please suggest a better way to replace the expressions as shown in above code.
Thanks


#2

Hi @syed.danish

You can group all of them into a single regex if that is what you are looking for

import re
str1='&?/:;%'
x=re.sub('[:\?&]',',',str1)
print(x)

#3

@anantguptadbl,
That helped. Thanks