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


Groups > comp.lang.python > #30163

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; 'def': 0.10; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'subject:sign': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'mid': 0.29; 'print': 0.32; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'text': 0.34; 'received:org': 0.36; 'method': 0.36; 'subject:with': 0.36; 'does': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'dollar': 0.71; 'subjectcharset:utf-8': 0.72; 'subject:dollar': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?
Date Wed, 26 Sep 2012 10:33:11 +0200
Organization None
References <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Gmane-NNTP-Posting-Host p5084bb09.dip.t-dialin.net
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1406.1348648406.27098.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348648406 news.xs4all.nl 6935 [2001:888:2000:d::a6]:44424
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30163

Show key headers only | View raw


iMath wrote:

> I only know  the dollar sign ($) will match a pattern from the
> end of a string,but which method does it work with ,re.match() or
> re.search()  ?

Why not try it out in the interactive interpreter? Here's the "deluxe 
version":

>>> def demo(pattern="mid$", texts=["start mid end", "start mid", "mid end", 
"mid"], matchers=[re.match, re.search]):
...     print "pattern:", pattern
...     for text in texts:
...             for matcher in matchers:
...                     name = matcher.__name__
...                     print u"\N{CHECK MARK}" + name if matcher(pattern, 
text) else (" "*(len(name)+1)),
...             print repr(text)
... 
>>> demo()
pattern: mid$
               'start mid end'
       ✓search 'start mid'
               'mid end'
✓match ✓search 'mid'

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


Thread

regular expression :  the dollar sign ($) work with re.match() or re.search()  ? iMath <redstone-cold@163.com> - 2012-09-26 00:38 -0700
  Re: regular expression :  the dollar sign ($) work with re.match() or re.search() Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-09-26 10:48 +0300
    Re: regular expression : the dollar sign ($) work with re.match() or re.search() Chris Angelico <rosuav@gmail.com> - 2012-09-26 17:57 +1000
    Re: regular expression :  the dollar sign ($) work with re.match() or re.search() Alister <alister.ware@ntlworld.com> - 2012-09-26 15:47 +0000
      Re: regular expression :  the dollar sign ($) work with re.match() or re.search() Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-09-26 19:29 +0300
  Re: regular expression : the dollar sign ($) work with re.match() or re.search() ? Peter Otten <__peter__@web.de> - 2012-09-26 10:33 +0200
  RE: regular expression :  the dollar sign ($) work with re.match() or re.search()  ? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-09-28 18:07 +0000
  Re: regular expression : the dollar sign ($) work with re.match() or re.search() ? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-28 12:32 -0600
  Re: regular expression :  the dollar sign ($) work with re.match() or re.search()  ? iMath <redstone-cold@163.com> - 2013-01-07 01:45 -0800
    Re: regular expression :  the dollar sign ($) work with re.match() or re.search()  � Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-07 09:54 +0000

csiph-web