Re: [Tutor] regexp: a bit lost

2010-10-01 Thread Alex Hall
On 10/1/10, Steven D'Aprano wrote: > On Sat, 2 Oct 2010 01:14:27 am Alex Hall wrote: >> >> Here is my test: >> >> s=re.search(r"[\d+\s+\d+\s+\d]", l) >> > >> > Try this instead: >> > >> > re.search(r'\d+\s+\D*\d+\s+\d', l) > [...] >> Understood. My intent was to ask why my regexp would match anyth

Re: [Tutor] regexp: a bit lost

2010-10-01 Thread Steven D'Aprano
On Sat, 2 Oct 2010 01:14:27 am Alex Hall wrote: > >> Here is my test: > >> s=re.search(r"[\d+\s+\d+\s+\d]", l) > > > > Try this instead: > > > > re.search(r'\d+\s+\D*\d+\s+\d', l) [...] > Understood. My intent was to ask why my regexp would match anything > at all. Square brackets create a charact

Re: [Tutor] regexp: a bit lost

2010-10-01 Thread Alex Hall
On 10/1/10, Steven D'Aprano wrote: > On Fri, 1 Oct 2010 12:45:38 pm Alex Hall wrote: >> Hi, once again... >> I have a regexp that I am trying to use to make sure a line matches >> the format: [c*]n [c*]n n >> where c* is (optionally) 0 or more non-numeric characters and n is >> any numeric charact

Re: [Tutor] regexp: a bit lost

2010-09-30 Thread Gerard Flanagan
with coffee: yes = """ v1 v2 5 2 someword7 3 """.splitlines()[1:] no = """ word 2 3 1 2 """.splitlines()[1:] import re pattern = "(\w*\d\s+?)(\w*\d\s+?)(\d)$" rx = re.compile(pattern) for line in yes: m = rx.match(line) assert m print([part.rstrip() for part in m.groups()]) f

Re: [Tutor] regexp: a bit lost

2010-09-30 Thread Steven D'Aprano
On Fri, 1 Oct 2010 12:45:38 pm Alex Hall wrote: > Hi, once again... > I have a regexp that I am trying to use to make sure a line matches > the format: [c*]n [c*]n n > where c* is (optionally) 0 or more non-numeric characters and n is > any numeric character. The spacing should not matter. These sh

Re: [Tutor] regexp: a bit lost

2010-09-30 Thread Gerard Flanagan
Alex Hall wrote: Hi, once again... I have a regexp that I am trying to use to make sure a line matches the format: [c*]n [c*]n n where c* is (optionally) 0 or more non-numeric characters and n is any numeric character. The spacing should not matter. These should pass: v1 v2 5 2 someword7 3 whi

[Tutor] regexp: a bit lost

2010-09-30 Thread Alex Hall
Hi, once again... I have a regexp that I am trying to use to make sure a line matches the format: [c*]n [c*]n n where c* is (optionally) 0 or more non-numeric characters and n is any numeric character. The spacing should not matter. These should pass: v1 v2 5 2 someword7 3 while these should not