0

I need to build regex to match all words starting with . but also white flag words like .well-known .. or some similar..

For now I have build the one that's complete opposite,, this one captures ONLY this one. I tried to find some regex symbol for invert but that doesn't exist I think..

location ~ /^(\.well-known) {
    deny all;
}

thx

Kresimir Pendic
  • 3,597
  • 1
  • 21
  • 28

3 Answers3

1

Here's an expression that works:

^(\.(?!well-known|other-forbidden-words|another-forbidden-word).+)$

Simply change the other words to white-listed words you want, and add more if need be.

ThePerplexedOne
  • 2,920
  • 15
  • 30
0

hm,,

I guess that I found my answer thanks to:

Invert match with regexp

this is the test that works now:

https://regex101.com/r/mS2wC6/2

and solution is this:

^(\.(?!well-known))

so ok, I think I got this grouping thing now..

hth, k

Community
  • 1
  • 1
Kresimir Pendic
  • 3,597
  • 1
  • 21
  • 28
0

well you don't have to add words in OR "|" condition you can simply do

$pattern = "/\.+(?:[a-zA-Z]|-)/";

which accepts anything that starts with . and contains - or alphabets.