import re str = 'abc' result = re.findall('...',str) print(result) # ['abc']
import re str = 'abcabcdabcdef' result = re.findall('.{3,5}',str) print(result) # ['abcab', 'cdabc', 'def']
import re str = '123abc456def' result = re.findall('\w+',str) print(result) # ['123abc456def']
import re str = 'abcdefgbcde' result = re.findall('abc|bcd',str) print(result) # ['abc', 'bcd']
import re str = 'abcdefg' result = re.match('abc', str) if result: print('Matched') else: print('Not matched') # Output: Matched
import re str = 'abcdefg' result = re.search('bcd', str) if result: print('Matched') else: print('Not matched') # Output: Matched
import re str = '123abc456def' result = re.findall('\d+', str) print(result) # ['123', '456']
import re str = 'aaa abba abbba' result = re.findall('(a+b+a*)', str) print(result) # ['aaa', 'abba', 'abbba']
import re str = 'abckdfjebcd' result = re.findall('(?<=abc).*?(?=bcd)', str) print(result) # ['kdfje']
import re str = '123abc456def' result = re.sub('\d+', 'number', str) print(result) # 'numberabcnumberdef'
标签: 百度统计