I'm trying to figure out how to validate mongoose URIs with regex. My current regex is this:

```none
^(mongodb:\/{2})(\w*?):{0,1}(\w*?)@{0,1}(\w+?):(\d+)\/(\w+?)

```

I need to be able to detect if a username and password is entered, i.e. 

```none
mongodb:username:password@localhost:27107/mydatabasename

```

So I need these cases to be invalid:

```none
mongodb://username:localhost:27107/adfaeadf
mongodb://username:@localhost:27107/adfaeadf
mongodb://:password@localhost:27107/adfaeadf

```

but have these cases be valid:

```none
mongodb://:@localhost:27107/mydatabasename
mongodb://@localhost:27107/mydatabasename
mongodb://localhost:27107/mydatabasename
mongodb:username:password@localhost:27107/mydatabasename

```

Any help would be appreciated