Using more than one flag in python re.findall

前端 未结 3 1925
一向
一向 2020-12-16 09:27

I would like to use more than one flag with the re.findall function. More specifically, I would like to use the IGNORECASE and DOTALL

相关标签:
3条回答
  • 2020-12-16 10:06

    Yes, but you have to OR them together:

    x = re.findall(pattern=r'CAT.+?END', string='Cat \n eND', flags=re.I | re.DOTALL)
    
    0 讨论(0)
  • 2020-12-16 10:10

    Is there a way to use more than one flag ?

    It wasn't mentioned, but you can use inline (?...) modifiers as well.

    x = re.findall(r'(?si)CAT.+?END', 'Cat \n eND')
    
    0 讨论(0)
  • 2020-12-16 10:14

    You can't put the flags within a tuple. Use the pipe character (OR operand) within your flags:

    x = re.findall(r'CAT.+?END','Cat \n eND',flags=re.I | re.DOTALL)
    
    0 讨论(0)
提交回复
热议问题