This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: re.error - for the search function in the re module
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Bnaya, eric.smith, ezio.melotti, mrabarnett, ronaldoussoren
Priority: normal Keywords:

Created on 2018-09-30 08:37 by Bnaya, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg326716 - (view) Author: Bnaya (Bnaya) Date: 2018-09-30 08:37
I was writing the following:'([+-*])', "54  *  83")

And I got the following runtime error:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 183, in search
    return _compile(pattern, flags).search(string)
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 286, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 930, in parse
    p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 426, in _parse_sub
    not nested and not items))
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 816, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 426, in _parse_sub
    not nested and not items))
  File "C:\Users\bnaya\AppData\Local\Programs\Python\Python37-32\lib\", line 580, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range +-* at position 2

Note that for different operators order, such as:'([+*-])', "54  *  83")
or'([*+-])', "54  *  83")
the function worked just fine.
msg326718 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2018-09-30 09:29
This is not a bug. You are searching for the character range from "+" to "*", which is an invalid range because "+" > "*".
msg326733 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-09-30 16:48
Perhaps we could improve that error message. If Ronald hand't pointed out the actual problem, it would have taken me a while to figure it out, too.

Maybe "bad character range +-* at position 2: starting character is after ending character"? Although I'll admit I haven't looked at the code to see if it knows enough to produce that kind of message without some serious refactoring.
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79032
2018-09-30 16:48:21eric.smithsetnosy: + eric.smith
messages: + msg326733
2018-09-30 09:29:01ronaldoussorensetstatus: open -> closed

type: crash -> behavior

nosy: + ronaldoussoren
messages: + msg326718
resolution: not a bug
stage: resolved
2018-09-30 08:37:44Bnayacreate