Can change this to the negative:

```php
if (!preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $dsn, $matches)) {
    return null;
}
```