Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78828
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: help with regex |
| Date | 2014-10-08 18:42 +1100 |
| References | <d68610fc-b22b-4dbe-994d-177b28932347@googlegroups.com> <m12m4v$mkt$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14673.1412754179.18130.python-list@python.org> (permalink) |
Peter Otten <__peter__@web.de> writes:
> >>> pattern = re.compile("(\d+)$")
> >>> match = pattern.search( "LINE: 235 : Primary Shelf Number (attempt 1): 1")
> >>> match.group()
> '1'
An alternative way to accomplish the above using the ‘match’ method::
>>> import re
>>> pattern = re.compile("^.*:(? *)(\d+)$")
>>> match = pattern.match("LINE: 235 : Primary Shelf Number (attempt 1): 1")
>>> match.groups()
('1',)
> See <https://docs.python.org/dev/library/re.html#search-vs-match>
Right. Always refer to the API documentation for the API you're
attempting to use.
--
\ “Without cultural sanction, most or all of our religious |
`\ beliefs and rituals would fall into the domain of mental |
_o__) disturbance.” —John F. Schumaker |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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