'How to match question mark "?" as regexp on nginx.conf location

I'd like to match question mark "?" as regexp on nginx.conf location.

For example, a URL pattern which I'd like to match is /something?foo=5 or /something?bar=8 (parameter only changeable).

Because nginx adopts RCPE, I can write the location on nginx.conf as follows:

location ~ ^/something\?.* {
}

The above doesn't match the URL pattern. How can I do that?

Also, the following is not my expectation.

location ~ ^/something?.* {
}

It'll match /something_foo_bar_buzz that I don't expect.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source