python - python 正则表达式 - ConnectionProfile:Database:MSSQL
问题描述
例如,我需要把这个词放在中间
ConnectionProfile:Database:MSSQL - result Database
有时文字会是
ConnectionProfile:Database:Oracle:ServiceName - i need the string after ConnectionProfile: till the next :
解决方案
通过提供的两个示例,您可以简单地使用字符串函数:
string = "ConnectionProfile:Database:MSSQL"
print(string.split(":")[1])
如果ConnectionProfile
碰巧在其他地方,您可以尝试:
ConnectionProfile:([^:]+)
并采取第一个捕获组,请参阅 regex101.com进行演示。
推荐阅读
- java - 如何检查数组中匹配的 int 值/字符串值?
- android - 如何根据姓名按字母顺序对联系人数据进行排序,当联系人没有姓名时,请改用电子邮件?
- javascript - 我在一个字符串数组上调用了 reduce。为什么这会产生一个数字?
- wordpress - 注意:试图在 WordPress save_post 动作钩子上获取非对象的属性
- selenium - 无法使用 crontab (MAC) 执行 selenium-side-runner
- javascript - 使用 Notification.image 或 Notification.icon
- php - 如何将数组格式化为xml?
- freeradius - 尝试连接/发送访问请求到 Freeradius 服务器时出错
- linux - 删除文件夹中除一个文件外的所有文件和目录
- python - 如何解释这个 Python 数组代码?