Regex to match golang sql dsn

huangapple go评论82阅读模式
英文:

Regex to match golang sql dsn

问题

我遇到了一个问题,无法匹配golang使用的DSN。所以我有两个应用程序(golang和php)使用相同的配置文件,该配置文件使用golang的dsn格式来声明DSN,我的想法是解析该dsn并将其用于PHP的代码中。有关正确的正则表达式的任何帮助吗?
谢谢!

英文:

I'm having troubles matching the DSN used by golang. So I have two applications (golang and php) using the same config file, and that config file states DSN using golang dsn format, my idea is parse that dsn and use it into PHP's code. Any help on the right regexp?
Thanks!

答案1

得分: 4

供参考,go-sql-driver项目使用此代码来解析DSN。他们不再使用正则表达式。

https://github.com/go-sql-driver/mysql/blob/master/utils.go#L74

这是他们以前使用的正则表达式:

https://github.com/go-sql-driver/mysql/blob/f4bf8e8e0aa93d4ead0c6473503ca2f5d5eb65a8/utils.go#L34

如果你查看新解析器的提交,它具有更好的性能(针对go 1.2和1.1进行了基准测试)。

https://github.com/go-sql-driver/mysql/commit/dc029498cb5a3efbe44e54dcb5cf080d451450fa

英文:

For reference the go-sql-driver project uses this to parse the dsn. They moved away from using a regex

https://github.com/go-sql-driver/mysql/blob/master/utils.go#L74

Here is the regex they used to use

https://github.com/go-sql-driver/mysql/blob/f4bf8e8e0aa93d4ead0c6473503ca2f5d5eb65a8/utils.go#L34

If you look at the commit for the new parser it has much better performance (benchmarked for go 1.2 and 1.1)

https://github.com/go-sql-driver/mysql/commit/dc029498cb5a3efbe44e54dcb5cf080d451450fa

huangapple
  • 本文由 发表于 2014年8月20日 18:26:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/25402391.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定