I'm totally stumped by this problem so I'm hoping someone can give me a little advice or point me in the right direction.
I have a file that looks like this: <SC>APPEAL<XC>40-24; 40-46; 42-46; 42-48; 42-62; 42-63 <SC>PROC GUIDE<XC>92<LT>1(b)(1) (i.e., <<SC>[chapter name]<XC>[multiple or single book page ranges]<SC>[chapter name]<XC>[multiple or single book page ranges]<LT>[code] but I want to change it so that it looks like this <1><SC>APPEAL<XC>40-24<LT>1(b)(1) <1><SC>APPEAL<XC>40-46<LT>1(b)(1) <1><SC>APPEAL<XC>42-46<LT>1(b)(1) <1><SC>APPEAL<XC>42-48<LT>1(b)(1) <1><SC>APPEAL<XC>42-62<LT>1(b)(1) <1><SC>APPEAL<XC>42-63<LT>1(b)(1) <1><SC>PROC GUIDE<XC>92<LT>1(b)(1) but I'm not at all sure how to do it. I've come up with a simlple function that will change the order of the text but I'm not sure how to break out def Switch(m): return '%s<LT>%s' % (m.group(2), m.group(1)) data = re.sub(r'''<1>(.*?)<LT>(.*?)\n''', Switch, data) But I'm still a long way from what I need. Any pointers would be greatly appreciated. Thanks, Greg -- http://mail.python.org/mailman/listinfo/python-list