我有以下格式的大字符串:'324/;.ke5 efwef dwe,werwrf <>i want this<> ergy;'56\45,> thu ;lokr<>i want this<> htur ;''\> htur> jur'我知道我可以按照以下方式做一些事情:result= text.partition('<>')[-1].rpartition('<>')[0]但这只会给我字符串中第一个和最后一个之间的内容,我如何遍历整个字符串并提取每个 标签对之间的内容? 最佳答案 您可以使用正则表达式和findall():>>> import re>>> s = "324/;.ke5 efwef dwe,werwrf <>i want this<> ergy;'56\45,> thu ;lokr<>i want this<> htur ;''\> htur> jur">>> re.findall(r"<>(.*?)<>", s)['i want this', 'i want this']其中,(.*?)是一个捕获组,可以在non-greedy模式下与任意字符多次匹配。关于python - Python:提取字符串中标签之间的所有子字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36295226/