Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102021
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: one more question on regex |
| Date | 2016-01-22 16:47 +0100 |
| Organization | None |
| Message-ID | <mailman.171.1453477686.15297.python-list@python.org> (permalink) |
| References | <n7ti39$7rt$1@gioia.aioe.org> |
mg wrote:
> python 3.4.3
>
> import re
> re.search('(ab){2}','abzzabab')
> <_sre.SRE_Match object; span=(4, 8), match='abab'>
>
>>>> re.findall('(ab){2}','abzzabab')
> ['ab']
>
> Why for search() the match is 'abab' and for findall the match is 'ab'?
I suppose someone thought it was convenient for findall to return the
explicit groups if there are any. If you want the whole match aka group(0)
you can get that with
>>> re.findall('(?:ab){2}','abzzabab')
['abab']
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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