Here is a reproducible example of what is needed. Lets say we have word HIV/AIDS. My question is how to write a regular expression to search for a string like this and replace it with strings HIV_AIDS.
This is the search pattern I have been able to write. Is this good in practice?
txt='DDD/VCD' #python 3.x
re1='((?:[a-z][a-z0-9_]*))' # Variable Name 1
re2='(\\/)' # Any Single Character 1
re3='((?:[a-z][a-z0-9_]*))' # Variable Name 2
rg = re.compile(re1+re2+re3,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
var1=m.group(1)
c1=m.group(2)
var2=m.group(3)
print ("("+var1+")"+"("+c1+")"+"("+var2+")"+"\n")
If my above code is good enough then please help me writing further code to replace the string(The sample I have already mentioned above).
I am still a beginner in regular expressions and want to write a simple regular expression for this using python-3.5x and above. I found re library in python but I am trying to write it without using the library. Any help will be appreciated. Thank you.