英文:
How to disallow a period in a JSON-schema pattern
问题
Sure, here's the translated content:
我想在JSON模式模式中的以下被禁止字符集中添加一个句号:
"pattern": "[^\"{}:, \t]+"
我的第一个想法是尝试:
"pattern": "[^\.\"{}:, \t]+"
但这会产生模式的解析错误。
我的下一个想法是尝试:
"pattern": "[^\\.\"{}:, \t]+"
但当我尝试验证我的YAML文件时,这并不具有所期望的属性。
我正在使用ajv作为我的JSON模式验证工具,并验证一个YAML文件。
英文:
I would like to add a period to the following banned character set in a JSON schema pattern:
"pattern": "[^\"{}:, \t]+"
My first thought was to try:
"pattern": "[^\.\"{}:, \t]+"
but this produces a parse error of the schema.
My next thought was to try:
"pattern": "[^\\.\"{}:, \t]+"
but this does not have the desired property when I try to validate my YAML file.
I am using ajv as my JSON schema validation tool, and I am validating a YAML file.
答案1
得分: 1
"As axiac and Diego D note, the period does not need to be escaped in the character class. However, in addition to that problem, the pattern was not matching anything because it lacked the prefix ^
and suffix $
. The final pattern is:
"pattern": "^[^\"{}:., \t]+$""
英文:
As axiac and Diego D note, the period does not need to be escaped in the character class. However, in addition to that problem the pattern was not matching anything because it lacked the prefix ^
and suffix $
. The final pattern is:
"pattern": "^[^\"{}:., \t]+$"
答案2
得分: 0
".
" 在字符类中不是特殊字符。只有 ^
、-
和 ]
是特殊字符,它们必须在字符类中进行转义。<br>
^
和 -
甚至可以在字符类中不进行转义,只要它们不被放在具有特殊意义的位置上。
你的成功尝试在字符类中添加了 .
和 \
。
只需在字符类中的某处添加 .
(不要在 ^
之前),就可以了:
"pattern": "[^\"{}:., \t]+"
英文:
.
is not a special character in character classes. Only ^
, -
and ]
are special characters and have to be escaped in character classes.<br>
^
and -
can even be used without escaping in a character class if they are not placed in positions where they have special meaning.
Your successful attempt added both .
and \
in the character class.
Just add .
somewhere in the character class (not before ^
) and that's all:
"pattern": "[^\"{}:., \t]+"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论