我想使用Python的分区和正则表达式来清理文本字符串。例如:正则表达式的Python分区字符串
testString = 'Tre Bröders Väg 6 2tr'
sep = '[0-9]tr'
head,sep,tail = testString.partition(sep)
head
>>>'Tre Br\xc3\xb6ders V\xc3\xa4g 6 2tr'
头仍包含2TR,我想删除。正则表达式我不太好,但不应该[0-9]做到这一点?
我希望从这个例子的输出是
head
>>> 'Tre Br\xc3\xb6ders V\xc3\xa4g 6
什么是你期待的输出? –
你甚至没有在这里使用正则表达式,为什么'[0-9]'会诀窍呢? –
添加了我期望的输出 – seb