Regex driving me crazy...

Patrick Maupin pmaupin at gmail.com
Wed Apr 7 22:45:21 EDT 2010


On Apr 7, 9:36 pm, Grant Edwards <inva... at invalid.invalid> wrote:
> On 2010-04-08, Patrick Maupin <pmau... 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

Sorry, my eyes completely missed your one-liner, so my criticism about
not posting a solution was unwarranted.  I don't think you and I read
the problem the same way (which is probably why I didn't notice your
solution -- because it wasn't solving the problem I thought I saw).

When I saw "And I am interested in the string that appears in the
third column, which changes as the test runs and then completes" I
assumed that, not only could that string change, but so could the one
before it.

I guess my base assumption that anything with words in it could
change.  I was looking at the OP's attempt at a solution, and he
obviously felt he needed to see two or more spaces as an item
delimiter.

(And I got testy because of seeing other IMO unwarranted denigration
of re on the list lately.)

Regards,
Pat



More information about the Python-list mailing list