help with regex

Peter Otten __peter__ at web.de
Wed Oct 8 08:38:10 CEST 2014


James Smith wrote:

> I want the last "1"
> I can't this to work:
> 
>>>> pattern=re.compile( "(\d+)$" )
>>>> match=pattern.match( "LINE: 235 : Primary Shelf Number (attempt 1): 1")
>>>> print match.group()

>>> pattern = re.compile("(\d+)$")
>>> match = pattern.search( "LINE: 235 : Primary Shelf Number (attempt 1): 
1")
>>> match.group()
'1'


See <https://docs.python.org/dev/library/re.html#search-vs-match>




More information about the Python-list mailing list