how to extract string inside single quotes using python script

后端 未结 3 480
-上瘾入骨i
-上瘾入骨i 2020-12-20 00:30

Have a set of string as follows

text:u\'MUC-EC-099_SC-Memory-01_TC-25\'
text:u\'MUC-EC-099_SC-Memory-01_TC-26\'
text:u\'MUC-EC-099_SC-Memory-01_TC-27\'
         


        
3条回答
  •  天涯浪人
    2020-12-20 01:37

    Use re.findall:

    >>> import re
    >>> strs = """text:u'MUC-EC-099_SC-Memory-01_TC-25'
    text:u'MUC-EC-099_SC-Memory-01_TC-26'
    text:u'MUC-EC-099_SC-Memory-01_TC-27'"""
    >>> re.findall(r"'(.*?)'", strs, re.DOTALL)
    ['MUC-EC-099_SC-Memory-01_TC-25',
     'MUC-EC-099_SC-Memory-01_TC-26',
     'MUC-EC-099_SC-Memory-01_TC-27'
    ]
    

提交回复
热议问题