Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102031
| From | Vlastimil Brom <vlastimil.brom@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: one more question on regex |
| Date | 2016-01-23 11:39 +0100 |
| Message-ID | <mailman.174.1453545581.15297.python-list@python.org> (permalink) |
| References | <n7ti39$7rt$1@gioia.aioe.org> <n7tj3j$9ra$1@gioia.aioe.org> <mailman.173.1453493453.15297.python-list@python.org> <n7ubhk$k9f$1@gioia.aioe.org> |
2016-01-22 23:47 GMT+01:00 mg <noOne@nowhere.com>: > Il Fri, 22 Jan 2016 21:10:44 +0100, Vlastimil Brom ha scritto: > >> [...] > > You explanation of re.findall() results is correct. My point is that the > documentation states: > > re.findall(pattern, string, flags=0) > Return all non-overlapping matches of pattern in string, as a list of > strings > > and this is not what re.findall does. IMHO it should be more reasonable > to get back the whole matches, since this seems to me the most useful > information for the user. In any case I'll go with finditer, that returns > in match object all the infos that anyone can look for. > -- > https://mail.python.org/mailman/listinfo/python-list Hi, I don't know the reasoning for this special behaviour of findall, but it seems to be documented explicitly: https://docs.python.org/3/library/re.html#re.findall "... If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. finditer is clearly much more robust for general usage. I only use findall for quick one-line tests (and there one has to account for this specificities - either by using non capturing groups or enclosing the whole pattern in a "main" group and use the first items in the resulting tuples. vbr
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
one more question on regex mg <noOne@nowhere.com> - 2016-01-22 15:32 +0000
Re: one more question on regex Peter Otten <__peter__@web.de> - 2016-01-22 16:47 +0100
Re: one more question on regex mg <noOne@nowhere.com> - 2016-01-22 15:50 +0000
Re: one more question on regex Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-01-22 21:10 +0100
Re: one more question on regex mg <noOne@nowhere.com> - 2016-01-22 22:47 +0000
Re: one more question on regex Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-01-23 11:39 +0100
csiph-web