正規表現 グループ コロン

(?:~) パターンのグループ
例)A(?:AB|CD) → AAB、ACDにマッチ
正規表現サンプル集

The better solution:

location ~ ^/phpmyadmin(?:/(.*))?$ {
    alias /home/phpmyadmin/$1;
}

Ensure that server has permissions to /home/phpmyadmin first.

It's all about regular expressions.

First of all, the ^ char means that you want to match from beginning of string and not somewhere in the middle. The $ at the end means matching to the end of the string.

The (?:) means non-capturing group - we don't want it in the capturing results, but we want to simple group some chars. We group it like this, because we want the / char to be a nonsignificant part of the child path, and not a significant part of the parent path.

How can I create a location in nginx that works with AND without a trailing slash? - Server Fault

https://regexr.com/