Python string pattern recognition/compression

前端 未结 6 918
隐瞒了意图╮
隐瞒了意图╮ 2021-02-15 14:45

I can do basic regex alright, but this is slightly different, namely I don\'t know what the pattern is going to be.

For example, I have a list of similar strings:

<
6条回答
  •  难免孤独
    2021-02-15 15:46

    How about subbing out the known text, and then splitting?

    import re
    [re.sub('(sometxt|moretxt)', ',', x).split(',') for x in lst]
    # results in
    [['a', '0', ''], ['b', '1', ''], ['aa', '10', ''], ['zz', '999', '']]
    

提交回复
热议问题