如何改进此regex(?<=//)(.*?)(?=@)
以从postgresql连接字符串中提取username:password。
我想从此字符串postgresql://db-admin-username@server:this-is-funny-passowrd/is-continuing=@127.0.0.1/dbname
中提取此字符串db-admin-username@server:this-is-funny-passowrd/is-continuing=
如果密码或用户名包含@
,则返回错误的字符串
它应该提取//
和最后一个@
字符之间的任何字符。
您可以使用
//(.*)@
在Python中,您可以使用
re.findall(r'//(.*)@', text)
.*
将从最左边的//
匹配到最右边的@
,从而返回所需的所有字符串。