Re: Regex driving me crazy...

2010-04-08 Thread Grant Edwards
On 2010-04-08, Steven D'Aprano wrote: > Even in 2010, there are plenty of programs that export data using fixed > width fields. If you want the columns to line up as the data changes, that's pretty much the only way to go. -- Grant Edwards grant.b.edwardsYow! But was he

Re: Regex driving me crazy...

2010-04-08 Thread J
On Thu, Apr 8, 2010 at 01:16, Kushal Kumaran wrote: > > Is there any particular reason you absolutely must extract the status > message?  If you already have a list of possible status messages, you > could just test which one of those is present in the line... Yes and no... Mostly, it's for the

Re: Regex driving me crazy...

2010-04-08 Thread Steven D'Aprano
On Wed, 07 Apr 2010 21:57:31 -0700, Patrick Maupin wrote: > On Apr 7, 9:51 pm, Steven D'Aprano > wrote: > > BTW, I don't know how you got 'True' here. > >> >>> re.split(' {2,}', s) == [x for x in s.split('  ') if x.strip()] >> True It was a copy and paste from the interactive interpreter. Her

Re: Regex driving me crazy...

2010-04-07 Thread Kushal Kumaran
On Thu, Apr 8, 2010 at 3:10 AM, J wrote: > Can someone make me un-crazy? > > I have a bit of code that right now, looks like this: > > status = getoutput('smartctl -l selftest /dev/sda').splitlines()[6] >        status = re.sub(' (?= )(?=([^"]*"[^"]*")*[^"]*$)', ":",status) >        print status >

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:51 pm, Steven D'Aprano wrote: BTW, I don't know how you got 'True' here. > >>> re.split(' {2,}', s) == [x for x in s.split('  ') if x.strip()] > True You must not have s set up to be the string given by the OP. I just realized there was an error in my non-regexp example, that actua

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:51 pm, Steven D'Aprano wrote: > This is one of the reasons we're so often suspicious of re solutions: > > >>> s = '# 1  Short offline       Completed without error       00%' > >>> tre = Timer("re.split(' {2,}', s)", > > ... "import re; from __main__ import s")>>> tsplit = Timer("[x f

Re: Regex driving me crazy...

2010-04-07 Thread Grant Edwards
On 2010-04-08, Patrick Maupin wrote: > 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

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:51 pm, Steven D'Aprano wrote: > On Wed, 07 Apr 2010 18:03:47 -0700, Patrick Maupin wrote: > > BTW, although I find it annoying when people say "don't do that" when > > "that" is a perfectly good thing to do, and although I also find it > > annoying when people tell you what not to do w

Re: Regex driving me crazy...

2010-04-07 Thread J
On Wed, Apr 7, 2010 at 22:45, Patrick Maupin wrote: > 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 ass

Re: Regex driving me crazy...

2010-04-07 Thread Steven D'Aprano
On Wed, 07 Apr 2010 18:03:47 -0700, Patrick Maupin wrote: > BTW, although I find it annoying when people say "don't do that" when > "that" is a perfectly good thing to do, and although I also find it > annoying when people tell you what not to do without telling you what > *to* do, Grant did giv

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:36 pm, Grant Edwards wrote: > On 2010-04-08, Patrick Maupin wrote:> On Apr 7, 4:47?pm, > Grant Edwards wrote: > >> On 2010-04-07, J wrote: > > >> > Can someone make me un-crazy? > > >> Definitely. ?Regex is driving you crazy, so don't use a regex. > > >> ? inputString = "# 1 ?Short

Re: Regex driving me crazy...

2010-04-07 Thread Grant Edwards
On 2010-04-08, James Stroud wrote: > Patrick Maupin wrote: >> BTW, although I find it annoying when people say "don't do that" when >> "that" is a perfectly good thing to do, and although I also find it >> annoying when people tell you what not to do without telling you what >> *to* do, and althou

Re: Regex driving me crazy...

2010-04-07 Thread Grant Edwards
On 2010-04-08, Patrick Maupin wrote: > On Apr 7, 4:47?pm, Grant Edwards wrote: >> On 2010-04-07, J 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% ?

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:02 pm, James Stroud wrote: > Patrick Maupin wrote: > > BTW, although I find it annoying when people say "don't do that" when > > "that" is a perfectly good thing to do, and although I also find it > > annoying when people tell you what not to do without telling you what > > *to* do, an

Re: Regex driving me crazy...

2010-04-07 Thread James Stroud
Patrick Maupin wrote: BTW, although I find it annoying when people say "don't do that" when "that" is a perfectly good thing to do, and although I also find it annoying when people tell you what not to do without telling you what *to* do, and although I find the regex solution to this problem to

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 7:49 pm, Patrick Maupin wrote: > On Apr 7, 4:40 pm, J wrote: > > > > > Can someone make me un-crazy? > > > I have a bit of code that right now, looks like this: > > > status = getoutput('smartctl -l selftest /dev/sda').splitlines()[6] > >         status = re.sub(' (?= )(?=([^"]*"[^"]*")

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 4:47 pm, Grant Edwards wrote: > On 2010-04-07, J 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(input

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 4:40 pm, J wrote: > Can someone make me un-crazy? > > I have a bit of code that right now, looks like this: > > status = getoutput('smartctl -l selftest /dev/sda').splitlines()[6] >         status = re.sub(' (?= )(?=([^"]*"[^"]*")*[^"]*$)', ":",status) >         print status > > Basicall

Re: Regex driving me crazy...

2010-04-07 Thread Grant Edwards
On 2010-04-07, J 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

Regex driving me crazy...

2010-04-07 Thread J
Can someone make me un-crazy? I have a bit of code that right now, looks like this: status = getoutput('smartctl -l selftest /dev/sda').splitlines()[6] status = re.sub(' (?= )(?=([^"]*"[^"]*")*[^"]*$)', ":",status) print status Basically, it pulls the first actual line of data fr