The modifier re. S

Findall () allows the findAll () function to automatically consider the effects of line breaks while searching, so that non-greedy matches can match line breaks.

Syntax format:

Re.findall (rules, text, re.s)Copy the code

Example:

import re
text='''123
asdfg456'''
r='123 (. *?) 456 '
a=re.findall(r,text,re.S)
print(a)
a=re.sub('\n'.' ',a[0])
print(a)
b=re.findall(r,text)
print(b)
Copy the code

Sub () function

It is used to clean the content extracted from the regular expression

Syntax format:

Re.sub (content to be replaced, replacement value, original value)Copy the code