首页 > 解决方案 > python 正则表达式 - ConnectionProfile:Database:MSSQL

问题描述

例如,我需要把这个词放在中间

ConnectionProfile:Database:MSSQL - result Database

有时文字会是

ConnectionProfile:Database:Oracle:ServiceName - i need the string after ConnectionProfile: till the next :

标签: pythonregex

解决方案


通过提供的两个示例,您可以简单地使用字符串函数:

string = "ConnectionProfile:Database:MSSQL"

print(string.split(":")[1])

如果ConnectionProfile碰巧在其他地方,您可以尝试:

ConnectionProfile:([^:]+)

并采取第一个捕获组,请参阅 regex101.com进行演示。


推荐阅读