python method
- search
-
- wordlist = [w for w in nltk.corpus.words.words(‘en‘ ) ifw.islower()]
- print [w for w in wordlist if re.search(‘ed$‘ ,w)]
- findall
-
- word = ‘supercalifragilisticexpialidocious‘
- print re.findall(‘[abcd]‘, word)
注意点:
word = ‘dsupercalifragilisticexpialidocious‘
print re.findall(‘[abcd]‘,word)
print re.findall(‘^[abcd]‘,word)
print re.findall(‘[^abcd]‘,word)
分别代表:
匹配abcd任意一个
在开头匹配abcd任意一个
匹配非abcd任意一个
时间: 2024-10-25 06:36:55