Re: Help with regexp please

2005-07-22 Thread Christopher Subich
Terry Hancock wrote: > I think this is the "regexes can't count" problem. When the repetition > count matters, you usually need something else. Usually some > combination of string and list methods will do the trick, as here. Not exactly, regexes are just fine at doing things like "first" and "l

Re: Help with regexp please

2005-07-22 Thread Terry Hancock
On Thursday 21 July 2005 11:39 pm, Felix Collins wrote: > Christopher Subich wrote: > > Scott David Daniels wrote: > Thanks to you both. Wow! what a quick response! > >string.rsplit('.',1)[0] > Clever Python! ;-) > Sorry, I mainly code in C so I'm not very Pythonic in my thinking. > Thanks agai

Re: Help with regexp please

2005-07-22 Thread Scott David Daniels
Felix Collins wrote: > Hi, > I'm not a regexp expert and had a bit of trouble with the following search. > I have an "outline number" system like > 1 > 1.2 > 1.2.3 > I want to parse an outline number and return the parent. Seems to me regex is not the way to go: def parent(string):

Help with regexp please

2005-07-22 Thread Felix Collins
Hi, I'm not a regexp expert and had a bit of trouble with the following search. I have an "outline number" system like 1 1.2 1.2.3 1.3 2 3 3.1 etc. I want to parse an outline number and return the parent. So for example... parent("1.2.3.4") returns "1.2.3" The only way I can figure is to

Re: Help with regexp please

2005-07-22 Thread Christopher Subich
Scott David Daniels wrote: > Felix Collins wrote: >> I have an "outline number" system like >> 1 >> 1.2 >> 1.2.3 >> I want to parse an outline number and return the parent. > > Seems to me regex is not the way to go: > def parent(string): > return string[: string.rindex('.')] Absolute

Re: Help with regexp please

2005-07-22 Thread Felix Collins
Christopher Subich wrote: > Scott David Daniels wrote: Thanks to you both. Wow! what a quick response! >string.rsplit('.',1)[0] Clever Python! ;-) Sorry, I mainly code in C so I'm not very Pythonic in my thinking. Thanks again... Felix -- http://mail.python.org/mailman/listinfo/python-lis