A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/103341.html below:

Help me use re better

Help me use re betterP Browning glpb at eis.bris.ac.uk
Tue Apr 24 02:38:10 EDT 2001
I've read AMK's RE HowTo but I think I'm missing something
obvious when it comes to substitutions. Any offers for
a more elegant solution to the program below gratefully
received. 

TIA Paul

------------------------
import string,re

directors = ['Prof A B Looney','Dr C D E Ftang','Ms H I J K Biscuit Barrel']
# I want no spaces between the initials
# Prof AB Looney
# Dr CDE Ftang
# Ms HIJK Biscuit Barrel

match_initials = re.compile(r'([A-Z] )+')

print
for director in directors:
    s = match_initials.search(director)
    inits = s.group(0)
    new_inits = string.replace(inits,' ','')
    new_director = string.replace(director,inits,new_inits + ' ')
    print director,new_director

-- 
--
 The Library, Tyndall Avenue, Univ. of Bristol, Bristol, BS8 1TJ, UK 
    E-mail: Paul.Browning at bristol.ac.uk  URL: http://www.bris.ac.uk/


More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4