Server_Name regular expression

I would like to syntax a regular expression which will match two server
names. The server names are example.com and www.example.com. In
particular,
a regular expression for www or nothing

I wrote the following regular expression (www.|)example.com Nginx
configuration file is compatible with Perl programming language. While
it
should work, it doesn’t seem to work. I cannot find the proper regular
expression. Does anyone have an idea how to synatx the regular
expression?

Thanks

Posted at Nginx Forum:

Hello!

On Thu, Aug 29, 2013 at 05:01:01AM -0400, christospap wrote:

I would like to syntax a regular expression which will match two server
names. The server names are example.com and www.example.com. In particular,
a regular expression for www or nothing

I wrote the following regular expression (www.|)example.com Nginx
configuration file is compatible with Perl programming language. While it
should work, it doesn’t seem to work. I cannot find the proper regular
expression. Does anyone have an idea how to synatx the regular expression?

How to use regular expressions in server_name directive is
documented here:

http://nginx.org/r/server_name

Note that regular expressions must be preceeded with “~” to
distinguish them from normal names.

Syntax of regular expressions per se is documented in the PCRE
library manual pages, see “man pcresyntax” for quick syntax
reference.


Maxim D.
http://nginx.org/en/donation.html

On 29 Aug 2013 10:01, “christospap” [email protected] wrote:

I would like to syntax a regular expression which will match two server
names. The server names are example.com and www.example.com. In
particular,
a regular expression for www or nothing

I wrote the following regular expression (www.|)example.com

Irrespective of your use of this in an nginx config, you have made a
mistake constructing the regex. It’s such a simple one that I feel
relatively sure that you’re a newcomer to such things, hence I would
suggest you find a regex primer (book|website) and study it carefully.

J

Hi,

Maybe http://regex101.com/ could help?

Cheers,
Jens

Från: [email protected] [mailto:[email protected]] För
Jonathan M.
Skickat: den 30 augusti 2013 10:54
Till: [email protected]
Ämne: Re: Server_Name regular expression

On 29 Aug 2013 10:01, “christospap”
<[email protected]mailto:[email protected]> wrote:

I would like to syntax a regular expression which will match two server
names. The server names are example.comhttp://example.com and
www.example.comhttp://www.example.com. In particular,
a regular expression for www or nothing

I wrote the following regular expression (www.|)example.comhttp://example.com

Irrespective of your use of this in an nginx config, you have made a
mistake constructing the regex. It’s such a simple one that I feel
relatively sure that you’re a newcomer to such things, hence I would
suggest you find a regex primer (book|website) and study it carefully.

J