Created
December 16, 2013 16:33
-
-
Save ctcarrier/7989957 to your computer and use it in GitHub Desktop.
Scala regex pattern to extract MongoDB connection info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> "mongodb://dbuser:[email protected]:22222/heroku_app1111" | |
res7: String = mongodb://dbuser:[email protected]:22222/heroku_app1111 | |
scala> val pattern = "^mongodb:\\/\\/([\\w]+):([\\w]+)@([\\w\\.]+):([\\d]+)\\/([\\w]+)".r | |
pattern: scala.util.matching.Regex = ^mongodb:\/\/([\w]+):([\w]+)@([\w\.]+):([\d]+)\/([\w]+) | |
scala> val pattern(user, password, host, port, db) = res7 | |
user: String = dbuser | |
password: String = dbpassword | |
host: String = 1111.mongolab.com | |
port: String = 22222 | |
db: String = heroku_app1111 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment