[Tutor] Question about an re

->Terry<- tvbare at socket.net
Thu Oct 27 23:44:50 CEST 2005


-----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<- <tvbare at socket.net> 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>
    / |  '     \    
   <   )        0    Linux 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-----



More information about the Tutor mailing list