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


Groups > comp.lang.python > #58292

Re: New to using re. Search for a number before a string.

Date 2013-11-01 21:40 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: New to using re. Search for a number before a string.
References <f241bc01-d10a-433f-b3af-b22d05a603d8@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1940.1383342016.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 01/11/2013 21:33, Captain Dunsel wrote:
> I have a text file that has lines with numbers occasionally appearing right before a person's name.  For example:
>
> COLLEGE:ENROLLMENT:COMPLETED EVALUATIONS:624309FUDD, ELMER
>
> where I want to search for the name "ELMER FUDD" and extract the number right in front of it "608309" when such a number appears but the length of the number is variable and using ?<= in a regular expression will only search for a fixed length.
>
> Any ideas appreciated!
>
How about searching with a pattern like r':(\d*)FUDD, ELMER'.

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


Thread

New to using re.   Search for a number before a string. Captain Dunsel <jonathan.nyquist@gmail.com> - 2013-11-01 14:33 -0700
  Re: New to using re.   Search for a number before a string. MRAB <python@mrabarnett.plus.com> - 2013-11-01 21:40 +0000
  Re: New to using re.   Search for a number before a string. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-11-02 09:06 +0200
  Re: New to using re.   Search for a number before a string. Justin Barber <jbarber@iliff.edu> - 2013-11-02 06:03 -0700
  Re: New to using re.   Search for a number before a string. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-02 13:31 +0000
  Re: New to using re.   Search for a number before a string. Captain Dunsel <jonathan.nyquist@gmail.com> - 2013-11-02 17:19 -0700
    Re: New to using re.   Search for a number before a string. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-03 00:27 +0000

csiph-web