1.Python代码
import re
def smallest_between_two(a, b, text):
return min(re.findall(re.escape(a)+"(.*?)"+re.escape(b),text), key=len)
def main():
print(smallest_between_two(' ', '(', 'def test()'))
print(smallest_between_two('[', ']', '[this one][not this one]'))
print(smallest_between_two('paste ', '/', '@paste "game_01/01"'))
if __name__ == "__main__":
main()
2.输出结果
test
this one
"game_01
版权声明:本文为博主原创文章,未经博主允许不得转载。
Python
- 上一篇:Python获取某字符串在文本中的位置
- 下一篇:Python获取指定行的数据