Question about metacharacter '*'

Devin Jeanpierre jeanpierreda at gmail.com
Mon Jul 7 16:27:59 EDT 2014


On Mon, Jul 7, 2014 at 11:51 AM,  <rxjwg98 at gmail.com> wrote:
> Would you give me an example using your pattern: `.*` -- `.`?
> I try it, but it cannot pass. (of course, I use it incorrectly)

Those are two patterns.

Python 3.4.1 (default, Jul  7 2014, 13:22:02)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.fullmatch(r'.', 'a')
<_sre.SRE_Match object; span=(0, 1), match='a'>
>>> re.fullmatch(r'.', 'ab')
>>> re.fullmatch(r'.', '')
>>>
>>> re.fullmatch(r'.*', 'a')
<_sre.SRE_Match object; span=(0, 1), match='a'>
>>> re.fullmatch(r'.*', 'ab')
<_sre.SRE_Match object; span=(0, 2), match='ab'>
>>> re.fullmatch(r'.*', '')
<_sre.SRE_Match object; span=(0, 0), match=''>

-- Devin



More information about the Python-list mailing list