[Tutor] Splitting at a capital letter in a string
Douglas N. Shawhan
lysdexia at crackrabbit.com
Sat Oct 30 05:26:06 CEST 2004
Yep. re looks like the only way. I was just wondering if I was missing
something in String.
Thanks! That's what I'll work with!
Bill Campbell wrote:
>On Fri, Oct 29, 2004, Douglas N. Shawhan wrote:
>
>
>>Is there a way to use the string module to split a string at a capital,
>>so that:
>>
>>HiImAStringWithCaps
>>
>>is rendered
>>
>>Hi Im A String With Caps
>>
>>I looked at the re module, and it looks as if it could be used for such
>>shenannigans...
>>
>>
>
>One way to do this would be:
>
>import re
>pat = re.compile('([A-Z])')
>s = pat.sub(r' \1', 'HiImAStringWithCaps').strip()
>
>The strip call gets rid of the first blank inserted.
>
>Bill
>--
>INTERNET: bill at Celestial.COM Bill Campbell; Celestial Systems, Inc.
>UUCP: camco!bill PO Box 820; 6641 E. Mercer Way
>FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
>URL: http://www.celestial.com/
>
>Democracy must be sometihng more than two wolves and a sheep voting on what
>to have for dinner -- James Bovard
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
More information about the Tutor
mailing list