One more regular expressions question

Jussi Salmela tiedon_jano at hotmail.com
Thu Jan 18 13:12:44 CET 2007


Victor Polukcht kirjoitti:
> Great thanks.
> 
> You post helped me so much!
> 
> My resulting regexp is:
> "(?P<var1>^(.*)\s*)\(((?P<var2>\d+))\)\s+((?P<var3>\d+))"
> 

If it doesn't have to be a regex:

#===================================================
s = '''\
Unassigned Number (1)                                    32
No Route To Destination (3)                              12
Normal call clearing (16)                                   2654
User busy (17)                                                 630
No user respond (18)                                        5
User alerting no answer (19)                             16
Call rejected (21)                                             3
Destination out of order (27)                             1
Invalid number format (28)                                32
Normal unspecified (31)                                   32
No channel available (34)                                 2
Temporary failure (41)                                      11
Switching equipment congestion (42)                4
Resource unavailable unspecified (47)               2
Bearer capability not authorized (57)                 73
Incomp. dest. / Non-existent CUG (88)              1
Recovery on timer expiry (102)                          2
Interworking, unspecified (127)                          5
'''

for row in s.split('\n')[:-1]:
     var1, var2 = row.split('(')
     var2, var3 = var2.split()
     var2 = var2[:-1]
     print var2, var3, var1
#===================================================

Cheers,
Jussi



More information about the Python-list mailing list