简体   繁体   English

XSD 中模式匹配的正则表达式

[英]Regex for pattern matching in XSD

I am writing XSD pattern restriction and I have the following strings that are valid我正在写 XSD 模式限制,并且我有以下有效的字符串

  1. $name $名称
  2. {.newvalue} {.newvalue}
  3. {testing} {测试}
  4. $name.testing $name.testing

And the below are invalid以下是无效的

  1. {$testing} {$测试}
  2. $testing} $测试}
  3. {testing {测试

No uppercase or @ symbol allowed.不允许大写或 @ 符号。

I have tried this <xs:pattern value="\{\w?[a-z0-9A-Z\.]*\}|\$\w+(\.[\w]+)*"/> this work partially but doesn't satisfy all conditions我试过这个<xs:pattern value="\{\w?[a-z0-9A-Z\.]*\}|\$\w+(\.[\w]+)*"/>这个工作部分但不满足所有条件

Any help is appreciated.任何帮助表示赞赏。

You may use您可以使用

<xs:pattern value="\$[a-z0-9]+(\.[a-z0-9]+)*|\{\.?[a-z0-9]+\}" />

The XSD regex is always anchored at the string start/end, see the regex demo . XSD 正则表达式始终锚定在字符串开始/结束处,请参阅正则表达式演示

Details细节

  • \$[a-z0-9]+(\.[a-z0-9]+)* - $ , one or more lowercase ASCII letters and then zero or mre sequences of a dot and one or more lowercase ASCII letters \$[a-z0-9]+(\.[a-z0-9]+)* - $ ,一个或多个小写 ASCII 字母,然后是零个或 mre 点序列和一个或多个小写 ASCII 字母
  • | - or - 或者
  • \{\.?[a-z0-9]+\} - { , an optional . \{\.?[a-z0-9]+\} - { ,可选的. , then 1 or more lowercase ASCII letters and then a } char. ,然后是 1 个或多个小写 ASCII 字母,然后是}字符。

Try \{?\$?[az.]+\}?试试\{?\$?[az.]+\}?

It's not easy to work out what the actual rules are: your attempted regex allows digits, but none of the examples use digits;弄清楚实际规则是什么并不容易:您尝试的正则表达式允许数字,但没有一个示例使用数字; and your attempted regex explicitly allows upper case, but your text suggests upper case isn't allowed.并且您尝试的正则表达式明确允许大写,但您的文字表明不允许大写。 And why do you mention '@' specifically, and not other punctuation characters?为什么你特别提到'@',而不是其他标点符号?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM