python - Removing the unwanted substrings from a series of strings -


i have series of strings given below

tata jaguor 1474 psnl series car tata nano pro 5864 series car tata indica 8586 k5478 tata nano 5864 e5478 tata bolero 8974 1567 series 

after stripping unwanted string resultant string expecting given respectively follows

  jaguor 1474   nano 5864    indica 8586_k5478   nano 5864_e5478   bolero 8974_1567 

i tried following code this,but not got expected result

vehiclename.replace("tata ","").replace("series","").replace("pro ","").replace(" car","") 

is there other better way this?

reobj = re.compile(r"tata ([\w ]+\d+).*?$", re.ignorecase | re.multiline) result = reobj.sub(r"\1", subject) 

http://rubular.com/r/jvvtcjltky

jaguor 1474 nano pro 5864 indica 8586 k5478 nano 5864 e5478 bolero 8974 1567 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -