Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'everyone!': 0.07; 'friday,': 0.09; 'lawrence': 0.09; 'occasionally': 0.09; "person's": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:number': 0.09; 'subject:using': 0.09; 'tismer': 0.09; 'python': 0.11; 'appreciated!': 0.16; 'invoice,': 0.16; 'newlines': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'slight': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'appears': 0.22; 'programming': 0.22; 'header:User-Agent:1': 0.23; 'url:moin': 0.24; 'second': 0.26; 'post': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'lines': 0.31; 'url:wiki': 0.31; 'extract': 0.31; 'file': 0.32; 'front': 0.32; 'text': 0.33; 'url:python': 0.33; 'could': 0.34; 'but': 0.35; 'thanks': 0.36; 'url:org': 0.36; 'subject:New': 0.37; 'christian': 0.38; 'to:addr :python-list': 0.38; 'help,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'length': 0.61; 'numbers': 0.61; 'world.': 0.61; 'name': 0.63; 'such': 0.63; 'subject:Search': 0.84; 'subject:before': 0.84; 'captain': 0.91; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: New to using re. Search for a number before a string. Date: Sun, 03 Nov 2013 00:27:43 +0000 References: <981273cf-2c82-4b58-b2d0-5f1beb0b0c53@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-26-212.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 In-Reply-To: <981273cf-2c82-4b58-b2d0-5f1beb0b0c53@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383438482 news.xs4all.nl 15952 [2001:888:2000:d::a6]:47397 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58356 On 03/11/2013 00:19, Captain Dunsel wrote: > On Friday, November 1, 2013 5:33:43 PM UTC-4, 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! > > Thanks for your help, everyone! > My invoice, like the proverbial cheque, is in the post :) Slight aside, in order to avoid the unwanted newlines above could you please read and action this, thanks https://wiki.python.org/moin/GoogleGroupsPython -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence