Regex driving me crazy...

Grant Edwards invalid at invalid.invalid
Wed Apr 7 22:36:49 EDT 2010


On 2010-04-08, Patrick Maupin <pmaupin at gmail.com> wrote:
> On Apr 7, 4:47?pm, Grant Edwards <inva... at invalid.invalid> wrote:
>> On 2010-04-07, J <dreadpiratej... at gmail.com> wrote:
>>
>> > Can someone make me un-crazy?
>>
>> Definitely. ?Regex is driving you crazy, so don't use a regex.
>>
>> ? inputString = "# 1 ?Short offline ? ? ? Completed without error ? ? 00% ? ? ? 679 ? ? ? ? -"
>>
>> ? print ' '.join(inputString.split()[4:-3])
[...]

> OK, fine.  Post a better solution to this problem than:
>
>>>> import re
>>>> re.split(' {2,}', '# 1  Short offline       Completed without error       00%')
> ['# 1', 'Short offline', 'Completed without error', '00%']

OK, I'll bite: what's wrong with the solution I already posted?

-- 
Grant




More information about the Python-list mailing list