Thanks for your reply.<br>
But I need to use a regex; my program deals with a large number
of  patterns, and I want to treat them in a uniform way (through
regex).<br><br><div><span class="gmail_quote">On 11/6/09, <b class="gmail_sendername">Chris Rebert</b> <<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Fri, Nov 6, 2009 at 8:04 AM, jorma kala <<a href="mailto:jjkk73@gmail.com">jjkk73@gmail.com</a>> wrote:<br> > Hi,<br> > I'm trying to write a re pattern to match a list of one or more numbers,<br> > each number is in the range of 1-15 value and the numbers are separated by<br>
 > spaces (but there are no spaces at the beginning and end of the string). For<br> > instance:<br> ><br> > "3"<br> > "1 14 8"<br> ><br> > but not:<br> ><br> > "22"<br>
 > " 5 11"<br> ><br> > I've come up with something like this<br> ><br> > re.compile("^((([1-9])|(1[0-8]))( +(?=[1-9]))*)+$")<br> ><br> > but I can't believe this has to be so complicated.<br>
 <br> <br>Your format seems so simple I have to ask why you're using regexes in<br> the first place.<br> <br> try:<br>    nums = [int(num) for num in line.split(" ")]<br> except ValueError:<br>    print "Invalid input"<br>
 <br> for num in nums:<br>    if num < 1 or num > 15:<br>        raise ValueError, "Number present which is outside of valid range"<br> <br> Cheers,<br> Chris<br> <br>--<br> <a href="http://blog.rebertia.com">http://blog.rebertia.com</a><br>
 </blockquote></div><br>