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


Groups > comp.lang.python > #30421

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

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: regular expression : the dollar sign ($) work with re.match() or re.search() ?
Date 2012-09-28 18:07 +0000
References <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1576.1348855696.27098.python-list@python.org> (permalink)

Show all headers | View raw


iMath wrote:
> Sent: Wednesday, September 26, 2012 2:39 AM
> To: python-list@python.org
> Subject: regular expression : the dollar sign ($) work with re.match() or re.search() ?
> 
> 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()  ?


You can try this on the interactive interpreter.
>>> re.match('hi$', 'xihi')
>>> re.search('hi$', 'xihi')
<_sre.SRE_Match object at 0x13FF7100>

Although, I think match does not work since match
only starts searching at the start of the string
while search looks for the pattern anywhere in the string.

>>> re.match('x.hi$', 'xihi')
<_sre.SRE_Match object at 0x15693BF0>

I guess you can consider re.match's pattern to be 
prefixed with '^'.

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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