re module (help with backslashes)

Stephen Boulet stephen.boulet at motorola.com
Wed Feb 5 17:34:57 EST 2003


I'm getting good results with the tk redemo.py matching this expression, but 
not in a python script.

I want to match 2 to 18 occurrences of a backslash plus any 3 alphanumeric 
characters. The goal is to replace contiguous blocks of backslash + 3 
alphanumerics with a tab.

This works fine in redemo: ((\\\\\w\w\w){2,18})+

By works fine, I mean that when "Highlight all matches" is selected, it finds 
everything I need.

This code returns 'None':

 >>> p=re.compile('((\\\\\w\w\w){2,18})+')
 >>> m = p.match(s)
 >>> print m
None

An example (ugly) string to match is:

s='J1Z0\\000\\000\\000\\000\\005\\352\\275\\360\\000\\000\\000\\000\\000\\000\\000\\012UUT_0\\000\\000\\000\\005\\352\\275\\360\\000\\000\\000\\000\\000\\000\\000\\0102_V\\000\\000\\000\\000\\000\\005\\352\\275\\360\\000\\000\\000\\000\\000\\000\\000\\007Ch1=11.2V_Ch2=0V_Ch3=0V\\000\\006\\024\\350\\320\\000JP\\350\\006\\024\\212\\340\\006\\024\\230\\210_degrees_C_RH\\000\\000\\000\\005\\352\\275\\360\\000\\000\\000\\000\\000\\000\\000\\007\n\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\0006_V\\000\\000\\000\\000\\000\\005\\352\\275\\360\\000\\000\\000\\000\\000\\000\\000\\007Ch1=11.8V_Ch2=0V_Ch3=0V\\000\\006\\024\\350\\320\\000JP\\350\\006\\024\\212\\340\\006\\024\\230\\210\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\n\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\00
0\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\00010_V\\000\\000\\000\\000\\005\\352\\275\\360\\000\\000\\000\\000\\000\\000\\000\\007Ch1=12.4V_Ch2=0V_Ch3=0V\\000\\006\\024\\350\\320\\000JP\\350\\006\\024\\212\\340\\006\\024\\230\\210\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\n\n\n'

or:

 >>> print s
J1Z0\000\000\000\000\005\352\275\360\000\000\000\000\000\000\000\012UUT_0\000\000\000\005\352\275\360\000\000\000\000\000\000\000\0102_V\000\000\000\000\000\005\352\275\360\000\000\000\000\000\000\000\007Ch1=11.2V_Ch2=0V_Ch3=0V\000\006\024\350\320\000JP\350\006\024\212\340\006\024\230\210_degrees_C_RH\000\000\000\005\352\275\360\000\000\000\000\000\000\000\007
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\0006_V\000\000\000\000\000\005\352\275\360\000\000\000\000\000\000\000\007Ch1=11.8V_Ch2=0V_Ch3=0V\000\006\024\350\320\000JP\350\006\024\212\340\006\024\230\210\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00010_V\000\000\000\000\005\352\275\360\000\000\000\000\000\000\000\007Ch1=12.4V_Ch2=0V_Ch3=0V\000\006\024\350\320\000JP\350\006\024\212\340\006\024\230\210\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000



 >>>

-- Stephen





More information about the Python-list mailing list