Matching patterns in Python

后端 未结 3 1048
失恋的感觉
失恋的感觉 2021-01-22 08:15

I have an XML file which contains the following strings:

abcdef
 pqrst


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-22 08:27

    Seems I did it for >:

    re.sub('(?','greater than', xml_string)
    

    ? - negative lookbehind assertion,

    ?! - negative lookahead assertion,

    (...)(...) is logical AND,

    so whole expression means "substitute all occurences of '>' which (does not start with ' " ') and (does not start with ' "') and ( does not end with ' ')

    case < is similar

提交回复
热议问题