Regex driving me crazy...
Patrick Maupin
pmaupin at gmail.com
Wed Apr 7 20:50:12 EDT 2010
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])
>
> > So any ideas on what the best way to proceed with this would be?
>
> Anytime you have a problem with a regex, the first thing you should
> ask yourself: "do I really, _really_ need a regex?
>
> Hint: the answer is usually "no".
>
> --
> Grant Edwards grant.b.edwards Yow! I'm continually AMAZED
> at at th'breathtaking effects
> gmail.com of WIND EROSION!!
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%']
>>>
Regards,
Pat
More information about the Python-list
mailing list