What regular expression engine does Nginx use? There are a lot of possibilities. More to the point, what flavor of syntax does it support, that is, what syntax features can I make use of?
Asked
Active
Viewed 2.1k times
91
-
23I'm surprised that this question has been closed. Determining the exact regex environment (and thus the available features) for Nginx is a basic, important, specific, and widely-applicable software-development problem. Furthermore, it's not well-documented in any obvious places in the Nginx documentation, nor is it easily found by a google search (unless you already know what PCRE is). Suggestions to improve the question to bring it on-topic are welcome. – David Eyk Jan 02 '13 at 21:58
-
It may have been closed because it was seen as not being programming-related. Your comment contains some good arguments for the content of the question. Also, can you add some greater detail about how knowing the answer will improve or alter how you will do programming? – bobs Jan 02 '13 at 22:24
-
1Sure. Anyone who has spent much time with regular expressions will know that there are many flavors of syntax. http://www.regular-expressions.info/refflavors.html has a good summary. Knowing the flavor allows me to tailor my patterns to use the best-available features in developing my web application (e.g. named capturing groups). – David Eyk Jan 02 '13 at 22:33
-
Sounds good. Edit your question with the information, so anyone that doesn't read comments will not try to close it again. – bobs Jan 02 '13 at 22:35
1 Answers
75
Nginx uses the PCRE library. The compile-time options list has some notes on this.

reallynice
- 1,289
- 2
- 21
- 41

Dave S.
- 6,349
- 31
- 33
-
7
-
3* [PCRE Pattern docs (long)](http://www.pcre.org/current/doc/html/pcre2pattern.html) * [PCRE syntax (more concise)](http://www.pcre.org/current/doc/html/pcre2syntax.html) – Ed Randall May 14 '18 at 15:53
-
Not really because for example `^/([A-Za-z0-9]+)/$` which is not valid PCRE (at least according to regex101, `An unescaped delimiter (\) must be escaped`) is valid in nginx... – the_nuts Sep 21 '22 at 07:01