Tag Archives: sre_constants.error: nothing to repeat at position

Pyhton Regularity Error: sre_constants.error: nothing to repeat at position

 

The wrong regular expression was written

1. Number of back bands

It’s embarrassing to write “d” as “B”

>>> pattern = re.compile(r'123\b*hello')

Output:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "E:\Anacoda3\Lib\re.py", line 233, in compile
    return _compile(pattern, flags)
  File "E:\Anacoda3\Lib\re.py", line 301, in _compile
    p = sre_compile.compile(pattern, flags)
  File "E:\Anacoda3\Lib\sre_compile.py", line 562, in compile
    p = sre_parse.parse(p, flags)
  File "E:\Anacoda3\Lib\sre_parse.py", line 856, in parse
    p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, False)
  File "E:\Anacoda3\Lib\sre_parse.py", line 415, in _parse_sub
    itemsappend(_parse(source, state, verbose))
  File "E:\Anacoda3\Lib\sre_parse.py", line 615, in _parse
    source.tell() - here + len(this))
sre_constants.error: nothing to repeat at position 2

Error reason: because the word boundary is the word boundary, the meaning of * is the occurrence of any times, that is to say, the word can only have one boundary, and can not occur any times, so this error will be reported