问题描述
令我惊讶的是,很难找到答案.
I am surprised that an answer to this is not easily found.
我正在制作JSON模式.我有一个对象,它的属性之一是包含正则表达式模式的字符串.此属性必须仅包含正则表达式.
I am in the process of making a JSON schema. I have an object and one of it's properties is a string containing a regex pattern. This property must contain only regex.
所以,这个问题实际上是两个问题合而为一:
So, this question is realistically two questions in one:
什么是描述正则表达式模式的正则表达式模式(请兼容javascript)?
What is the regex pattern that describes regex patterns (javascript-compatible please)?
第二,如何将其应用于JSON模式(在"pattern"
属性中,甚至在"patternProperty"
属性中)?
Secondly, how do I apply this to JSON schema (in the "pattern"
property or even in the "patternProperty"
property)?
:我不知道什么目的需要您在"patternProperty"
中应用它,但是外面有人会发现它有用
: I have no idea what purpose would require you to apply this in "patternProperty"
, but someone out there could find it useful
注意::由于JSONschema是JSON且JSON是基于JavaScript的,因此JavaScript脚本编写者可能会找到解决方案(对于问题的JSONschema方面)以及对他们有用的问题脚本.
NOTE: Since, JSONschema is JSON and JSON is JavaScript-based, JavaScript scripters may find the solution (to the JSONschema-side of the question), as well as the problem, useful in their scripts.
推荐答案
正则表达式可以带有嵌套的括号.
Regexes can have nested parentheses.
因此,它们不能用正则表达式描述.
抱歉.
Therefore, they are not describable by a regular expression.
Sorry.
这篇关于正则表达式描述正则表达式模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!