Regex for different system subdomains or domain

Asked

Viewed 236 times

2

I am developing a system where each user will have their subdomain according to their login but I will also allow them to configure their own domain.

As I am developing locally, I have also added some rules for everything to work on my local machine.

To solve my problem I started to make a regex in case there are no strings it does not let pass but I do not know how to allow other.

For example that list of domains:

sistema.com.br            // não pode casar
local.dev                 // não pode casar
cliente.local.dev         // tem que casar
cliente.sistema.com.br    // tem que casar
app.sistema.com.br        // não pode casar essa
app.local.dev             // não pode casar essa
www.dominio.com.br        // regex casa, já está certo
subdominio.dominio.com.br // tem que casar
dominio.com.br            // regex casa, já está certo

Currently my regular expression is like this:

^(?!.*(sistema\.com\.br|local\.dev)).*$

What I need to solve is for this regex to marry any subdomains except the subdomain app and also could not marry the main domains sistema.com.br and local.dev

I’m not finding a solution since I still don’t know how to work with denied lists along with permitted lists.

Summarizing what I’m trying to do is marry any domain (including domains with subdomains) except the ones in the list below:

sistema.com.br
local.dev
app.sistema.com.br
app.sistema.dev
  • I did something similar recently and solved it this way. I pointed all domains to the same physical place and treated each domain using php I get the name of the domino that the user is accessing and give the proper treatment with my URL friendly system.

  • This wouldn’t work for me. I need to solve with regular expression anyway.

2 answers

1


You can try the following expression:

/^((?!\b(app|sistema|local)\b)(.\w{2,3})*)(.\w{2,})(.\w{2,5})*.\w{2,3}$/igm

See it working with any domain: http://refiddle.com/jt2a

inserir a descrição da imagem aqui

  • The domain would have to be dynamic (any domain). The idea would be: marry any domain other than: system.com.br or local.dev or app.sistema.com.br or app.local.dev. Any other domain could accept.

  • Vi your msg now, I’ll update... wait a little.

  • Update made! Test there and tell me if everything was all right ok?

  • It worked perfectly. Thank you very much for your help :)

0

I found the solution with the following regular expression:

^(?!(sistema\.com\.br|app\.sistema\.com\.br|local\.dev|app\.local\.dev)).*$

Browser other questions tagged

You are not signed in. Login or sign up in order to post.