re.DOTALL

Full name
re.DOTALL
Library
re
Syntax

re.DOTALL

Description

The re.DOTALL search modifier forces the symbol . represent any character, including the newline symbol \n.

Parameters

The re.DOTALL search modifier takes no arguments.

Examples

In this example we start with the following text and search pattern:

text = "dogs and cats play\ndogs and cats eat"
pattern = r".dog"

Note that the text includes a line break:

print(text)
dogs and cats play
dogs and cats eat

By default, the search for the regular expression will not find any matches since there is no "dog" string preceded by a character: in the first line "dog" occupies the beginning of the string and in the second it is preceded by a newline symbol which does not return a match to the symbol .:

re.findall(pattern, text)
[]

However, if the re.DOTALL argument is included, the newline symbol does return a match to the symbol .:

re.findall(pattern, text, flags = re.DOTALL)
['\ndog']
Submitted by admin on Sat, 05/22/2021 - 08:27