Skip to content

Instantly share code, notes, and snippets.

@ctcarrier
Created December 16, 2013 16:33
Show Gist options
  • Save ctcarrier/7989957 to your computer and use it in GitHub Desktop.
Save ctcarrier/7989957 to your computer and use it in GitHub Desktop.
Scala regex pattern to extract MongoDB connection info
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