简体   繁体   中英

Regular Expression: Matching letters or letters with numbers only

I have been trying to build a regex which can capture:

  1. All letter strings, such as 'abc', 'def'
  2. Strings with letters and numbers such as '123a', 'a23b', 'df4'

but not to capture pure numbers such as:

  1. '123'
  2. '123.23'

Any help is appreciated!

try this

 import re
    >>> if(re.match(".*[a-z].*",'abc123')):
        print "1"


    1
    >>> if(re.match(".*[a-z].*",'123')):
        print "1"


    >>> if(re.match(".*[a-z].*",'123abc')):
        print "1"


    1

您可能正在寻找这个: \\d*[a-zA-Z]+\\d*[a-zA-Z]*

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