Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'mrab': 0.05; 'matches': 0.07; 'subject:Question': 0.07; 'string': 0.09; 'character,': 0.09; 'literal': 0.09; 'matched': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'times,': 0.14; 'useful,': 0.14; 'a),': 0.16; 'forth.': 0.16; 'once.': 0.16; 'quite.': 0.16; 'subject:skip:m 10': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'pieces': 0.19; 'written': 0.21; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'specifies': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'related': 0.29; "doesn't": 0.30; 'characters': 0.30; 'mix': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'usually': 0.31; 'decimal': 0.31; 'another': 0.32; 'url:python': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'url:listinfo': 0.36; 'useful': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'example,': 0.37; 'so,': 0.37; 'form,': 0.38; 'question,': 0.38; 'previous': 0.38; 'ability': 0.39; 'url:mail': 0.40; 'is.': 0.60; 'numbers': 0.61; 'matter': 0.61; 'first': 0.61; 'more': 0.64; 'natural': 0.68; 'below:': 0.68; 'jul': 0.74; 'power': 0.76; 'regexp': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=NDPBfQPtHLDP6RxT4qP7mjqUi2jNZkskxgPJlz37BjU=; b=J4NwpVQ/n48C59BxrX6o50cWH/snCzrN5kte2MzNG0slkA20lFO3kEmdnWcI4PrYfK Fbofb1I3nOeZBBWCmkmwoMDv8nnVjx2v5xSnugIadCU9fXcVkP8cGLC6rkFc3McAqRkh EaVt2/NtsESdhHMN/BjD711eR3xtge+zVQt6RnAOBABPzIxVlnxSX795o15Z9gbuqQmj 3ENvZaszmagFdghQRNGPkV/QBg52lvkwOUoxd6xycfb07D9Psl8076yVgOcylTdSsmmQ UO9QkEeofIcX8GoMmy0e6deIeno0Ce0nDjZjULPft/j/GgEpm5MliW+mYCE8As15D9Ms J5Vg== X-Received: by 10.224.50.195 with SMTP id a3mr3991850qag.47.1404661853993; Sun, 06 Jul 2014 08:50:53 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <53B96C0A.3030302@mrabarnett.plus.com> References: <3f7ecf04-b881-4e79-aa59-893580090468@googlegroups.com> <53B96C0A.3030302@mrabarnett.plus.com> From: Devin Jeanpierre Date: Sun, 6 Jul 2014 08:50:13 -0700 Subject: Re: Question about metacharacter '*' To: MRAB Content-Type: text/plain; charset=UTF-8 Cc: "comp.lang.python" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404662273 news.xs4all.nl 2832 [2001:888:2000:d::a6]:59128 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74026 In related news, the regexp I gave for numbers will match "1a". -- Devin On Sun, Jul 6, 2014 at 8:32 AM, MRAB wrote: > On 2014-07-06 13:09, Devin Jeanpierre wrote: >> >> On Sun, Jul 6, 2014 at 4:51 AM, 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