Re: Regular expression to capture model numbers

2009-04-24 Thread Piet van Oostrum
> John Machin (JM) wrote: >JM> On Apr 24, 1:29 am, Piet van Oostrum wrote: >>> obj = re.compile(r'(?:[a-z]+[-0-9]|[0-9]+[-a-z]|-+[0-9a-z])[-0-9a-z]*', >>> re.I) >JM> Understandable and maintainable, I don't think. Suppose that instead >JM> the first character is limited to being alphabeti

Re: Regular expression to capture model numbers

2009-04-23 Thread John Machin
On Apr 24, 1:29 am, Piet van Oostrum wrote: > > John Machin (JM) wrote: > >JM> On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote: > >>> Requirements: > >>>   The text must contain a combination of numbers, alphabets and hyphen > >>> with at least two of the three elements present. > >JM> Un

Re: Regular expression to capture model numbers

2009-04-23 Thread Piet van Oostrum
> John Machin (JM) wrote: >JM> On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote: >>> Requirements: >>>   The text must contain a combination of numbers, alphabets and hyphen >>> with at least two of the three elements present. >JM> Unfortunately(?), regular expressions can't express comp

Re: Regular expression to capture model numbers

2009-04-22 Thread Aahz
In article <1bbafe6d-e3bc-4d90-8a0a-0ca82808b...@d14g2000yql.googlegroups.com>, wrote: > >My quick attempt is below: >obj = re.compile(r'\b[0-9|a-zA-Z]+[\w-]+') re.findall(obj, 'TestThis;1234;Test123AB-x') >['TestThis', '1234', 'Test123AB-x'] > >This is not working. What isn't working? Why

Re: Regular expression to capture model numbers

2009-04-22 Thread John Machin
On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote: > My quick attempt is below: > obj = re.compile(r'\b[0-9|a-zA-Z]+[\w-]+') 1. Provided the remainder of the pattern is greedy and it will be used only for findall, the \b seems pointless. 2. What is the "|" for? Inside a character class, | has n

Regular expression to capture model numbers

2009-04-22 Thread krishnapostings
My quick attempt is below: obj = re.compile(r'\b[0-9|a-zA-Z]+[\w-]+') >>> re.findall(obj, 'TestThis;1234;Test123AB-x') ['TestThis', '1234', 'Test123AB-x'] This is not working. Requirements: The text must contain a combination of numbers, alphabets and hyphen with at least two of the three eleme