Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DOTALL S (single line)

  • .
  • DOTALL
  • S

if re.DOTALL is given, . will match any character. Including newlines.

import re

line = 'Before <div>content</div> After'

text = '''
Before
<div>
content
</div>
After
'''

match = re.search(r'<div>.*</div>', line)
if match:
    print(f"line '{match.group(0)}'");

match = re.search(r'<div>.*</div>', text)
if match:
    print(f"text '{match.group(0)}'");

print('-' * 10)

match = re.search(r'<div>.*</div>', line, re.DOTALL)
if match:
    print(f"line '{match.group(0)}'");

match = re.search(r'<div>.*</div>', text, re.DOTALL)
if match:
    print(f"text '{match.group(0)}'");