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


Groups > comp.lang.python > #78827

Re: help with regex

From Peter Otten <__peter__@web.de>
Subject Re: help with regex
Date 2014-10-08 08:38 +0200
Organization None
References <d68610fc-b22b-4dbe-994d-177b28932347@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.14672.1412750317.18130.python-list@python.org> (permalink)

Show all headers | View raw


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>

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


Thread

help with regex James Smith <bjlockie@lockie.ca> - 2014-10-07 21:25 -0700
  Re: help with regex Peter Otten <__peter__@web.de> - 2014-10-08 08:38 +0200
  Re: help with regex Ben Finney <ben+python@benfinney.id.au> - 2014-10-08 18:42 +1100

csiph-web