Issue 20810: literal re fails to match (original) (raw)
Issue20810
Created on 2014-02-28 19:06 by Jonathan.Epstein, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg212463 - (view) | Author: Jonathan Epstein (Jonathan.Epstein) | Date: 2014-02-28 19:06 |
All 3 of these regex's should match, but in practice only m2 does. Found deep in the bowels of debugging a larger problem. import re mainProjectsPath = '/groups/larvalolympiad/larvalolympiad/Projects/' m1 = re.match('larvalolympiad',mainProjectsPath) m2 = re.match('.*larvalolympiad.*',mainProjectsPath) m3 = re.match('/larvalolympiad/',mainProjectsPath) print(m1) print(m2) print(m3) | ||
msg212468 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2014-02-28 19:23 |
re.match requires a match at the beginning of the string. From the docs: "If zero or more characters at the beginning of string match the regular expression pattern, ...". If you switch to re.search, they'll all match: >>> re.search('larvalolympiad',mainProjectsPath) <_sre.SRE_Match object at 0xffed54f0> >>> re.match('.*larvalolympiad.*',mainProjectsPath) <_sre.SRE_Match object at 0xffed5870> >>> re.search('/larvalolympiad/',mainProjectsPath) <_sre.SRE_Match object at 0xffed54f0> | ||
msg212469 - (view) | Author: Jonathan Epstein (Jonathan.Epstein) | Date: 2014-02-28 19:24 |
Sorry, this was dumb. Thanks for your patience. On Fri, Feb 28, 2014 at 2:23 PM, Eric V. Smith <report@bugs.python.org>wrote: > > Eric V. Smith added the comment: > > re.match requires a match at the beginning of the string. From the docs: > "If zero or more characters at the beginning of string match the regular > expression pattern, ...". > > If you switch to re.search, they'll all match: > > >>> re.search('larvalolympiad',mainProjectsPath) > <_sre.SRE_Match object at 0xffed54f0> > > >>> re.match('.*larvalolympiad.*',mainProjectsPath) > <_sre.SRE_Match object at 0xffed5870> > > >>> re.search('/larvalolympiad/',mainProjectsPath) > <_sre.SRE_Match object at 0xffed54f0> > > ---------- > nosy: +eric.smith > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue20810> > _______________________________________ > |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:57:59 | admin | set | github: 65009 |
2014-03-01 01:55:29 | ezio.melotti | set | stage: resolved |
2014-02-28 19:24:21 | Jonathan.Epstein | set | messages: + |
2014-02-28 19:24:01 | eric.smith | set | status: open -> closedresolution: not a bug |
2014-02-28 19:23:39 | eric.smith | set | nosy: + eric.smithmessages: + |
2014-02-28 19:09:34 | yselivanov | set | nosy: + yselivanov |
2014-02-28 19:06:48 | Jonathan.Epstein | create |