正则表达式(?:)(?=)(?!)(?<=)(?2020-12-30 本文已影响0人
Aeddaimport re
# pattern = re.compile('windows(?:2000|95)') # ['windows2000', 'windows95']
# pattern = re.compile('windows(?=2000|95)') # ['windows', 'windows']
# pattern = re.compile('windows(?!2000|95)') # ['windows']
# pattern = re.compile('(?<=123)windows') # ['windows']
# pattern = re.compile('(?<!,)windows') # ['windows', 'windows']
pattern = re.compile('(?<![3,])windows') # ['windows']
s = '''windows2000地方,windows95,123windows'''
print(re.findall(pattern,s))
在要提取的数据的前面的话,需要用小于号
re.search('(?<=://).*?(?=/)','https://www.amazon.fr/reviews/top-reviewers').group()
# www.amazon.fr
import re
# pattern = re.compile('windows(?:2000|95)') # ['windows2000', 'windows95']
# pattern = re.compile('windows(?=2000|95)') # ['windows', 'windows']
# pattern = re.compile('windows(?!2000|95)') # ['windows']
# pattern = re.compile('(?<=123)windows') # ['windows']
# pattern = re.compile('(?<!,)windows') # ['windows', 'windows']
pattern = re.compile('(?<![3,])windows') # ['windows']
s = '''windows2000地方,windows95,123windows'''
print(re.findall(pattern,s))
在要提取的数据的前面的话,需要用小于号
re.search('(?<=://).*?(?=/)','https://www.amazon.fr/reviews/top-reviewers').group()
# www.amazon.fr