Pcre2_compile() failed: missing closing parenthesis in "^/test/([a-z]"

I have a VPS. Even with a simple conf file, I get this error: pcre2_compile() failed: missing closing parenthesis in “^/test/([a-z]”

Here is the VERY basic conf file for the test:

server {
    listen 80;

    location ~ ^/test/([a-z]{2})$ {
        return 200;
    }
}

Here are a few commands to give you some information:

ldd /usr/sbin/nginx | grep -i pcre
    libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0


dpkg -l | grep pcre
ii  libpcre2-8-0:amd64                10.42-1                        amd64        New Perl Compatible Regular Expression Library- 8 bit runtime files


echo '^/test/([0-9]{4})$' | pcre2test
PCRE2 version 10.42 2022-12-11
^/test/([0-9]{4})$
** Invalid pattern delimiter '^' (x5e).


printf '/^\\/test\\/([0-9]{4})$/\n1234\n' | pcre2test
PCRE2 version 10.42 2022-12-11
/^\/test\/([0-9]{4})$/
1234
No match


ldd /usr/sbin/nginx | grep -i pcre
dpkg -l | grep pcre
    libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f776e977000)
ii  libpcre2-16-0:amd64               10.42-1                        amd64        New Perl Compatible Regular Expression Library - 16 bit runtime files
ii  libpcre2-32-0:amd64               10.42-1                        amd64        New Perl Compatible Regular Expression Library - 32 bit runtime files
ii  libpcre2-8-0:amd64                10.42-1                        amd64        New Perl Compatible Regular Expression Library- 8 bit runtime files
ii  libpcre2-posix3:amd64             10.42-1                        amd64        New Perl Compatible Regular Expression Library - posix-compatible runtime files
ii  pcre2-utils                       10.42-1                        amd64        New Perl Compatible Regular Expression Library - utilities


cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Hello,
Did you try putting the regex in quotes?

server {
    listen 80;

    location ~ "^/test/([a-z]{2})$" {
        return 200;
    }
}

Yes, that solves the problem; I'll keep you posted! Thanks.

Yeah, it's confirmed! Thanks.