Re: [Tutor] Question about an re
- -: \d+/?\d* - - - -ie 1 or more digits followed by 0 or 1 slashes followed by 0 or more digits. this looks like it'll also accept invalid data, such as 1/ ... i think there's some more tweaking involved to get it so that if there's a '/', there is at least one digit afterwards. -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2006,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about an re
w chun wrote: - -: \d+/?\d* - - - -ie 1 or more digits followed by 0 or 1 slashes followed by 0 or more digits. this looks like it'll also accept invalid data, such as 1/ ... i think there's some more tweaking involved to get it so that if there's a '/', there is at least one digit afterwards. \d+(/\d+)? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about an re
OR tests for the truth of the first thing then the truth of the second. The first part of your OR is always true, so it doesn't test the second. What you really want to do is look for a digit and then look for more digits or a slash and some more digits. So: : \d(\d+|/\d+) but this is easier by just allowing an optional slash in the digits: : \d+/?\d* ie 1 or more digits followed by 0 or 1 slashes followed by 0 or more digits. http://www.regular-expressions.info/ is a brilliant tutorial on regexs and http://www.weitz.de/regex-coach/ is a great program for testing them out before you put them in your code. Hope this helps Ed On 27/10/05, -Terry- [EMAIL PROTECTED] wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 os - Slackware py - 2.4.1 I'm trying to grab the value 10 in Visibility: 10 mile(s):0 but sometimes the value looks like Visibility: 1/2 mile(s):0 My not working regex looks like re.compile(': \d+|: \d/\d') If I'm understanding right, this should match either or, but it doesn't work for the fractional reading. Can someone steer me in the right direction and explain what I'm doing wrong? Thanks much, - -- Terry ,-~~-.___. Terry Randall tvbareATsocketDOTnet / | ' \ )0Linux Counter Project User# 98233 \_/, ,-' // / \-'~;/~~~(0) / __/~| / | If only Snoopy had Slackware... =( __| (| He is your friend, your partner, your defender, your dog. You are his life, his love, his leader. He will be yours, faithful and true, to the last beat of his heart. You owe it to him to be worthy of such devotion.-- Unknown (Best viewed with a mono-spaced font.) -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.7 (GNU/Linux) iD8DBQFDYFhdQvSnsfFzkV0RAoPyAJ4jfwjWJ1eoqDatB6Hmg07XbUMGLQCeP/eQ ognaRmmfxNlDW249jRqYE2g= =Txx/ -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about an re
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Today (Oct 27, 2005) at 9:29am, Ed Singleton spoke these wise words: - -OR tests for the truth of the first thing then the truth of the second. - - - -The first part of your OR is always true, so it doesn't test the second. - - - -What you really want to do is look for a digit and then look for more - -digits or a slash and some more digits. - - - -So: - - - -: \d(\d+|/\d+) - - - -but this is easier by just allowing an optional slash in the digits: - - - -: \d+/?\d* - - - -ie 1 or more digits followed by 0 or 1 slashes followed by 0 or more digits. - - - -http://www.regular-expressions.info/ is a brilliant tutorial on regexs - -and http://www.weitz.de/regex-coach/ is a great program for testing - -them out before you put them in your code. - - - -Hope this helps - - - -Ed - - - -On 27/10/05, -Terry- [EMAIL PROTECTED] wrote: - - -BEGIN PGP SIGNED MESSAGE- - - Hash: SHA1 - - - - - - os - Slackware - - py - 2.4.1 - - - - I'm trying to grab the value 10 in - - - - Visibility: 10 mile(s):0 - - - - but sometimes the value looks like - - - - Visibility: 1/2 mile(s):0 - - - - My not working regex looks like - - - - re.compile(': \d+|: \d/\d') - - - - If I'm understanding right, this should match either or, - - but it doesn't work for the fractional reading. Ok, I get it now. Thanks for the help and the links Ed. Works like a charm and I changed it to also grab another variation I found thanks to your help. Visibility: less than 1/4 mile(s):1 Thanks again, - -- Terry ,-~~-.___. Terry Randall tvbareATsocketDOTnet / | ' \ )0Linux Counter Project User# 98233 \_/, ,-' // / \-'~;/~~~(0) / __/~| / | If only Snoopy had Slackware... =( __| (| He is your friend, your partner, your defender, your dog. You are his life, his love, his leader. He will be yours, faithful and true, to the last beat of his heart. You owe it to him to be worthy of such devotion.-- Unknown (Best viewed with a mono-spaced font.) -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.7 (GNU/Linux) iD8DBQFDYUpVQvSnsfFzkV0RAvckAJ4xrve8QaTnMUa+UO9lDjxIv+A48ACdFhcF yu6FTTtTkZiGD7GrVi98SGg= =B5Pl -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor