我有一個字符串模式(對於xml
測試報告)按以下模式:解析字符串模式 - Python的
'testsets.testcases.[testset].[testcase]-[date-stamp]'
例如:
a='testsets.testcases.test_different_blob_sizes.TestDifferentBlobSizes-20150430130436'
我知道,我總是可以解析testset
和testcase
名做:
temp = a.split("-")[0]
current = temp.split(".")
testset = '.'.join(current[:-1]) + ".py"
testcase = current[-1]
然而,我想要使用更加pythonic的方式來完成,如regex
或任何其他表達式,我會在一行中做到這一點。我怎麼能做到這一點?
[Python正則表達式示例]的可能重複(http://stackoverflow.com/questions/11171045/python-regular-expression-example) –
你突然開始使用什麼's'和它的'name' ? –
@MalikBrahimi對不起會更新這個問題 – cybertextron