Regex URI Matching With Bitwarden

4 min readJul 1, 2022

This post probably falls into the category of being completely obvious, but considering I went for a fairly long time without realizing it, maybe this will help someone else out as well. I periodically access a variety of different vCenter instances via their web interface, all of which have a very similar naming convention. For the sake of this post, I’ll pretend that it’s:


All of the instances are linked up with Active Directory, so I log into each of them with the same AD credentials. Typically what I’d do when I needed to access one is fire up my password manager (I use Bitwarden; I’m sure you can probably do this with a plethora of other password managers as well… and if you aren’t using a password manager you should start!), and then manually copy and paste the password I needed from it.

Going through this process wasn’t awful, but it also wasn’t particularly convenient. I still ended up typing in my username — or at least starting to type it and then auto-completing it from my browser — and then having to:

  1. Click on the browser extension for my password manager.
  2. Type enough of the entry where I have my AD credentials saved to find it. (Mercifully, the search box automatically has focus in the Firefox extension for Bitwarden.)
  3. Click the button to copy the password.
  4. Click back into the password field in vCenter.
  5. Paste the password.

There are certainly worse things, but this became annoying enough that I figured there had to be a better way. After spending just enough time looking at the Bitwarden UI to feel embarrassed I hadn’t thought about this sooner considering how easy it was to fix, I realized there’s an option to change how Bitwarden checks for URI matches:

Screenshot of the URI match detection used by Bitwarden on the entry for my Tumblr account.

When editing an entry in Bitwarden, just click the gear icon visible in the screenshot above, and then the URI match drop-down will appear. While I could have gone with a lazier option like Starts with and just used https://vcenter, I wanted to be a bit more methodical. So I instead opted for the Regular expression option. I’m not about to pretend that I’m an expert — or even particularly fluent — with regular expressions, but the beauty of the Internet is that I don’t have to be. In this case, I just needed to match on one or more digits; I knew I would always have at least one. I was fairly certain I could match on that via (\d+), but regex101 saved me from having to wonder about it.

With my relatively simple requirements, I went to regex101 and added a few test cases; one of the biggest benefits of the site is that I can add as many data points as I want to validate my single regular expression against a wide array of possible options rather than having to test each of them individually. This tends to be more useful when writing scripts that could be dealing with hundreds or thousands of potential cases I need to test, but it works fine for this as well. 🙂

Then I entered my regex:


There are a few things worth noting. First is that the forward slash character / is considered to be a delimiter, so it must be escaped. The other one that I find trips people up much more frequently is that the period . is also a special character which should be escaped; if unescaped, it technically matches any character other than a newline. That’s why it shows up differently in regex101 if I don’t escape it; the site recognizes it as something that it needs to check for a match upon:

regex101 test with an intentionally unescaped period in a URI.

If I escape the period, like I did with the first one in the URI, it just shows as a normal string match:

regex101 test with both period of the URI escaped.

While it’s unlikely to matter when filling in URIs to something like Bitwarden, it certainly can make a difference in coding, so I think it’s a good habit to get into. For example, here I once again removed the escape from the second period, and then in my test I replaced the period character with an at symbol @ which still shows as a match because it isn’t a newline:

regex101 test with an @ symbol in the URI showing that it matches a period in the expression.

Again, I’m not too likely to accidentally enter a URI that contains something like this into Bitwarden, but being mindful of it is a good habit to form for using regex elsewhere.

With the update made to my entry in Bitwarden, now I can quickly and easily enter my credentials automatically into every vCenter instance I access with the following, heavily truncated process from before:

  1. Click on the browser extension for my password manager.
  2. Click on the entry for my AD credentials.

Much better!