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

Prasad, Ramit ramit.prasad at jpmorgan.com
Fri Sep 28 14:07:57 EDT 2012


iMath wrote:
> Sent: Wednesday, September 26, 2012 2:39 AM
> To: python-list at 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.  


More information about the Python-list mailing list