Wednesday, May 2, 2012

Python Regular Expressions - removing all characters passed a certain character

I have a few regular expressions, for example, that looks like this
98374D90
483D39
3843930D393



Right now I have the python code taking out all characters and keeping integers like so:



ws = 98374D90
clean = re.sub("\D", "", ws)


Which leaves me with 9837490 but what I need it to do is once it reaches the character "D" it drops the D and everything after it so 98374D90 would result in 98374 how would I do this?



Thanks for the help.





No comments:

Post a Comment