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(), re.MULTILINE and "^" broken
Type: Stage:
Components: Regular Expressions Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: effbot Nosy List: effbot, notz
Priority: normal Keywords:

Created on 2004-09-03 19:09 by notz, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
re_bug.py notz, 2004-09-03 19:09 Python source illustrating the bug.
Messages (2)
msg22351 - (view) Author: Pat Notz (notz) Date: 2004-09-03 19:09
The re.match() function does not appear to respect the 
re.MULTILINE flag when matching on "^".  It does, however, 
behave as documented with respect to "$".  I've observed this with 
Python 2.2.2 and 2.3.3 on Linux, RedHat 9.0.  Below is some 
sample code and output that illustrates the issue.  As illustrated, 
re.search() behaves as expected.

$ cat /proc/version 
Linux version 2.4.20-28.9psycho (root@sahp5069) (gcc version 
3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #1 SMP Wed Feb 18 07:
08:55 MST 2004

$ python
Python 2.2.2 (#1, Feb 10 2004, 13:57:46) 
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
>>> 

$ python re_bug.py
Pattern is '^hello world$' with flags = 10
Testing: "hello world
thank you"... match_pass search_pass
Testing: "ahem
hello world"... match_fail search_pass
Testing: "ahem
hello world
thank you"... match_fail search_pass


I would expect the match to work (match_pass and search_pass) 
on all of the sample strings.
msg22352 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2004-09-03 21:34
Logged In: YES 
user_id=38376

Match never scans the string: if something doesn't match at 
the beginning, it won't match at all.  There's even a separate 
section in the documentation on re.match and ^:

http://docs.python.org/lib/matching-searching.html

</F>
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40865
2004-09-03 19:09:41notzcreate