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

MULTILINE M

  • ^
  • $
  • MULTILINE
  • M

if re.MULTILNE is given, ^ will match beginning of line and $ will match end of line

import re

line = 'Start   blabla End'

text = '''
prefix
Start
blabla
End
postfix
'''

regex = r'^Start[\d\D]*End$'
m = re.search(regex, line)
if (m):
    print('line')

m = re.search(regex, text)
if (m):
    print('text')

print('-' * 10)

m = re.search(regex, line, re.MULTILINE)
if (m):
    print('line')

m = re.search(regex, text, re.MULTILINE)
if (m):
    print('text')
line
----------
line
text