2
votes

I wonder if someone has achieved what I'll post here. In order to allow a template to be created under a certain path, there is a flag allowedPaths that receives a regex.

So, if I want my template "test" to appear only under /content/www/xx/xx/test-templates and child elements, I can do this:

/content/www/.*/.*/test-templates(/.*)?

But what if I want to make the opposite? I want the template "test" to appear in every /content/www/xx/xx/ node and beyond, EXCEPT /content/www/xx/xx/test-templates and children?

I have tried several ways but no luck so far. Do you have some hint regarding this?

Thanks!

1
Not sure if this flavor supports regex, but you can try ^(?!/content/www/[^/]*/[^/]*/test-templates)/content/www/[^/]*/[^/]*(/.*) or (?!/content/www/[^/]*/[^/]*/test-templates)/content/www/[^/]*/[^/]*(/.*)Wiktor Stribiżew
Checking it right now. I think this is a very good solution! I'll put results here in a few.SnwBr
regexr.com/3ckfm seems that is almost almost working! :) it is still excluding /content/www/us/en/test-templates-calendar and /content/www/us/en/test-templates-calendar/ which should be accepted.SnwBr

1 Answers

2
votes

You can always restrict a more generic pattern with a lookahead. Here is an expression that should work for you:

^(?!/content/www/[^/]*/[^/]*/test-templates(?:/|$))/content/www/[^/]*/[^/]*(/.*)

See demo.

  • ^ - matches the start of string
  • (?!/content/www/[^/]*/[^/]*/test-templates(?:/|$)) - makes sure the next substring is not /content/www/<some_node>/<some_node>/test-templates, followed by the end of string ($) or /
  • /content/www/[^/]*/[^/]*(/.*) - matches /content/www/<some_node>/<some_node> followed with optional / and zero or more characters other than a newline