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.
我想知道是否有人实现了我在这里发布的消息。为了允许在特定路径下创建模板,有一个标志允许路径接收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:
因此,如果我希望我的模板“test”只出现在/content/www/xx/ test-template和子元素下,我可以这样做:
/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?
但是如果我想做相反的事情呢?我希望模板“test”出现在每个/content/www/xx/ node以及其他地方,除了/content/www/xx/xx/test模板和子模板?
I have tried several ways but no luck so far. Do you have some hint regarding this?
我已经尝试了好几种方法,但到目前为止没有运气。你对此有什么暗示吗?
Thanks!
谢谢!
1 个解决方案
#1
2
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/
- (? ! /内容/ www /[^ /]* /[^ /]* /测试模板(?:/ | $))——确保接下来的子字符串不是/内容/ www / < some_node > / < some_node > /测试模板,紧随其后的是字符串(美元)或/的结束
-
/content/www/[^/]*/[^/]*(/.*)
- matches/content/www/<some_node>/<some_node>
followed with optional/
and zero or more characters other than a newline - (^ /)/内容/ www / * /(^ /)*(/ . *)-匹配/内容/ www / < some_node > / < some_node >紧随其后可选/除了换行符和零个或多个字符
#1
2
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/
- (? ! /内容/ www /[^ /]* /[^ /]* /测试模板(?:/ | $))——确保接下来的子字符串不是/内容/ www / < some_node > / < some_node > /测试模板,紧随其后的是字符串(美元)或/的结束
-
/content/www/[^/]*/[^/]*(/.*)
- matches/content/www/<some_node>/<some_node>
followed with optional/
and zero or more characters other than a newline - (^ /)/内容/ www / * /(^ /)*(/ . *)-匹配/内容/ www / < some_node > / < some_node >紧随其后可选/除了换行符和零个或多个字符