我有一个类似于以下字符串的字符串:
'My substring1. My substring2: My substring3: My substring4'
理想情况下,我的目标是使用Pythonregex从这个字符串中提取‘my subing2’.然而,我也会对类似的结果感到满意.我的底线2:‘
到目前为止,我能够提取出
'. My substring2: My substring3:'
使用
"\.\s.*:"
Alternatively, I have been able to extract - by using Wiktor Stribiżew's solution that deals 使用 a somewhat similar problem posted in How can i extract words from a string before colon and excluding \n from them in python using regex -
'My substring1. My substring2'
specifically 使用
r'^[^:-][^:]*'
然而,经过多个小时的搜索和try (我对regex还很陌生),我一直无法将两个结果组合到一个有效的regex表达式中,该表达式将从我前面提到的字符串中提取‘my subing2’.
如果有人能帮我找出正确的正则表达式来提取‘my subing2’,那我就再好不过了.谢谢!