Wrong regular expression
1. \b followed by the quantity
Wrongly written \d to \b, embarrassing!
1
|
>>> 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
Reason for error: Since \b is a word boundary, * means that it appears any number of times, that is, a word can only have one boundary, and it cannot appear any number of times, so this error will be reported