I have a String in this format:
mydb://<user>:<password>@<host>:27017
And I would like to use Java regexp in order to extract the <user> and <password> strings from the String. What would be the best way doing so?
EDIT:
I would like to be able to use this regexp in the String’s replace method so that I’m left only with the relevant user and password Strings
You can use this regex (Pattern)
And then capture group #1 and #2 will have your user and password respectively.
Code:
OUTPUT:
EDIT: Based on your comments: if you want to use String methods then: