[Zope] Finding a phone number in a python script
Dieter Maurer
dieter@handshake.de
Thu, 24 Oct 2002 21:05:16 +0200
Schmidt, Allen J. writes:
> I have a block of text that contains a phone number in the format of
> 888/123-4567 and I need to identify that sequence when it occurs and somehow
> extract it, and return it to Zope without the slash or the dash.
>
> Without regex in Python scripts, is there any way to do this?
You can use "split":
If "s" contains the phone number string "888/123-4567", then
s.split('/')[0] gives you "888"
s.split('-')[-1] gives you "4567"
s.split('-')[0].split('/')[-1] gives you "123"
Dieter