美文网首页
正则表达式(?:)(?=)(?!)(?<=)(?

正则表达式(?:)(?=)(?!)(?<=)(?

作者: Aedda | 来源:发表于2020-12-30 14:26 被阅读0次
    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
    

    相关文章

      网友评论

          本文标题:正则表达式(?:)(?=)(?!)(?<=)(?

          本文链接:https://www.haomeiwen.com/subject/bydhoktx.html