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.

classification
Title: bug on re.search using the char ,-:
Type: Stage: resolved
Components: IDLE Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: DPalharini, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-09-21 01:46 by DPalharini, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg251187 - (view) Author: Diego Palharini (DPalharini) Date: 2015-09-21 01:46
Using the packet re for regular expressions I found a strange behavior with the following command:


re.search("[,-:]","89")

it returns that one of those chars exists into the string "89" or whatever number you may use.
msg251199 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-09-21 04:25
This is how regular expressions work.

https://docs.python.org/3/library/re.html#regular-expression-syntax
Ranges of characters can be indicated by giving two characters and separating them by a '-', for example [a-z] will match any lowercase ASCII letter, [0-5][0-9] will match all the two-digits numbers from 00 to 59, and [0-9A-Fa-f] will match any hexadecimal digit. If - is escaped (e.g. [a\-z]) or if it’s placed as the first or last character (e.g. [a-]), it will match a literal '-'.
History
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69387
2015-09-21 04:25:28serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg251199

resolution: not a bug
stage: resolved
2015-09-21 01:46:04DPalharinicreate