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: re.match ignores optional flags when receiving a compiled regex pattern
Type: behavior Stage:
Components: Regular Expressions Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: bcorfman, rhettinger
Priority: normal Keywords:

Created on 2007-12-19 15:40 by bcorfman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg58808 - (view) Author: Brandon Corfman (bcorfman) Date: 2007-12-19 15:40
Python's documentation for the re.match function is match(pattern,
string, [flags]) where pattern can be either a regex string or a
compiled regex object. If it's a compiled regex object, then supplying
an optional flag to re.match (in my case, re.IGNORECASE) doesn't work
and, more to the point, fails silently. I think this should throw an
exception if it's not going to work.

See
http://mysite.verizon.net/bcorfman/2007/12/something-i-hate-about-pythons-re.html
for a discussion.

A possible change (proposed by effbot) is below:
Index: re.py
===================================================================
--- re.py       (revision 52330)
+++ re.py       (working copy)
@@ -224,6 +224,7 @@
         return p
     pattern, flags = key
     if isinstance(pattern, _pattern_type):
+        assert not flags
         return pattern
     if not sre_compile.isstring(pattern):
         raise TypeError, "first argument must be string or compiled
pattern"
msg58816 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-12-19 18:14
Fixed.  See commit 59573.
History
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46002
2007-12-19 18:14:17rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg58816
2007-12-19 17:57:17rhettingersetassignee: rhettinger
nosy: + rhettinger
versions: + Python 2.6, - Python 2.5
2007-12-19 15:40:03bcorfmancreate