简体   繁体   中英

How to use re.compile in Python if I want to match alphabetic word only

I'm learning the RE module for Python and doing some experiment. I have question regarding using expression, here is the example:

name = 'abc123def456'
m = re.compile('.*[^0-9]').match(name)
m.group()
print m

Result is 'abc123def'

What should I do if I want to totally take out the numeric number

Thank you!

You can extract all occurrences of alphabets and concatenate them to get just the alphabets in the string. See below:

"".join(re.findall("[a-zA-Z]+",name))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM