re.DEBUG

Full name
re.DEBUG
Library
re
Syntax

re.DEBUG

Description

The re.DEBUG search modifier displays debug information regarding the function being executed.

Parameters

The re.DEBUG search modifier takes no arguments.

Examples

If we start from the following search and text pattern:

pattern = r'(cat)s?'
text = 'my cat and your cats are pretty'

...we can get debug information about the execution of the re.search function with the following code:

re.search(pattern, text, flags = re.DEBUG)

SUBPATTERN 1 0 0
  LITERAL 99
  LITERAL 97
  LITERAL 116
MAX_REPEAT 0 1
  LITERAL 115

 0. INFO 12 0b1 3 4 (to 13)
      prefix_skip 0
      prefix [0x63, 0x61, 0x74] ('cat')
      overlap [0, 0, 0]
13: MARK 0
15. LITERAL 0x63 ('c')
17. LITERAL 0x61 ('a')
19. LITERAL 0x74 ('t')
21. MARK 1
23. REPEAT_ONE 6 0 1 (to 30)
27.   LITERAL 0x73 ('s')
29.   SUCCESS
30: SUCCESS
<re.Match object; span=(3, 6), match='cat'>


Submitted by admin on Wed, 05/19/2021 - 08:17