python 换行匹配

  • 2019 年 10 月 7 日
  • 筆記

re.compile() 函数接受一个标志参数叫 re.DOTALL ,在这里非常有用。 它可以让正则表达式中的点(.)匹配包括换行符在内的任意字符。比如:

comment = re.compile(r'/*(.*?)*/', re.DOTALL)   comment.findall(text2)   [' this is an multiline comment ']       
Exit mobile version