F
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 do two searches feeding the output of
the first into the input of the second.
Here is the code fragment...
m = re.compile(r'(\d+\.)+').match("1.2.3.4")
n = re.compile(r'\d+(\.\d+)+').match(m.string[m.start():m.end()])
parentoutlinenumber = n.string[n.start():n.end()]
parentoutlinenumber
1.2.3
How do I get that into one regexp?
Thanks for any help...
Felix
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 do two searches feeding the output of
the first into the input of the second.
Here is the code fragment...
m = re.compile(r'(\d+\.)+').match("1.2.3.4")
n = re.compile(r'\d+(\.\d+)+').match(m.string[m.start():m.end()])
parentoutlinenumber = n.string[n.start():n.end()]
parentoutlinenumber
1.2.3
How do I get that into one regexp?
Thanks for any help...
Felix