Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74026

Re: Question about metacharacter '*'

References <3f7ecf04-b881-4e79-aa59-893580090468@googlegroups.com> <CABicbJKUOsKW77LGkDF-1E52AmsPpTJq=GAUTA2PLpff+7fxNQ@mail.gmail.com> <53B96C0A.3030302@mrabarnett.plus.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2014-07-06 08:50 -0700
Subject Re: Question about metacharacter '*'
Newsgroups comp.lang.python
Message-ID <mailman.11545.1404662273.18130.python-list@python.org> (permalink)

Show all headers | View raw


In related news, the regexp I gave for numbers will match "1a".

-- Devin

On Sun, Jul 6, 2014 at 8:32 AM, MRAB <python@mrabarnett.plus.com> wrote:
> On 2014-07-06 13:09, Devin Jeanpierre wrote:
>>
>> On Sun, Jul 6, 2014 at 4:51 AM,  <rxjwg98@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I just begin to learn Python. I do not see the usefulness of '*' in its
>>> description below:
>>>
>>>
>>>
>>>
>>> The first metacharacter for repeating things that we'll look at is *. *
>>> doesn't
>>> match the literal character *; instead, it specifies that the previous
>>> character
>>> can be matched zero or more times, instead of exactly once.
>>>
>>> For example, ca*t will match ct (0 a characters), cat (1 a), caaat (3 a
>>> characters), and so forth.
>>>
>>>
>>>
>>> It has to be used with other search constraints?
>>
>>
>> (BTW, this is a regexp question, not really a Python question per se.)
>>
>> That's usually when it's useful, yeah. For example, [0-9] matches any
>> of the characters 0 through 9. So to match a natural number written in
>> decimal form, we might use the regexp [0-9][0-9]*, which matches the
>> strings "1", "12", and "007", but not "" or "Jeffrey".
>>
>> Another useful one is `.*` -- `.` matches exactly one character, no
>> matter what that character is. So, `.*` matches any string at all.
>>
> Not quite. It won't match a '\n' unless the DOTALL flag is turned on.
>
>
>> The power of regexps stems from the ability to mix and match all of
>> the regexp pieces in pretty much any way you want.
>>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question about metacharacter '*' rxjwg98@gmail.com - 2014-07-06 04:51 -0700
  Re: Question about metacharacter '*' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-06 05:09 -0700
    Re: Question about metacharacter '*' rxjwg98@gmail.com - 2014-07-07 11:51 -0700
      Re: Question about metacharacter '*' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-07 13:27 -0700
      Re: Question about metacharacter '*' Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-07 22:50 +0100
  Re: Question about metacharacter '*' MRAB <python@mrabarnett.plus.com> - 2014-07-06 16:32 +0100
  Re: Question about metacharacter '*' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-06 08:50 -0700
    Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 09:24 -0700
      Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 09:32 -0700
      Re: Question about metacharacter '*' Roy Smith <roy@panix.com> - 2014-07-06 12:47 -0400
        Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 10:38 -0700
          Re: Question about metacharacter '*' Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 10:58 -0700

csiph-web