我如何改进此正则表达式 (?<=\/\/)(.*?)(?=\@)
以从postgresql连接字符串中提取username:password。
我想db-admin-username@server:this-is-funny-passowrd/is-continuing=
从这个字符串中提取这个字符串postgresql://db-admin-username@server:this-is-funny-passowrd/[email protected]/dbname
如果密码或用户名包含以下内容,它将返回错误的字符串 @
它应该提取//
最后一个@
字符之间的任何内容。
您可以使用
//(.*)@
在Python中,您可以使用
re.findall(r'//(.*)@', text)
在.*
将匹配从最左边//
,直到最右边@
,从而返回所有你需要的字符串。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句