【问题标题】:Meaning of "[A-Z]{4}\d{2}-\d{4}" in an XSD patternXSD 模式中“[A-Z]{4}\d{2}-\d{4}”的含义
【发布时间】:2015-09-25 10:41:41
【问题描述】:

谁能用一个有效数据参数的例子解释一下这个模式的含义。

<xsd:simpleType>
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="[A-Z]{4}\d{2}-\d{4}"/>
  </xsd:restriction>
</xsd:simpleType>

【问题讨论】:

  • 4 个大写字符后跟 2 位数字,然后是连字符,然后是另外 4 位数字

标签: regex xml xsd


【解决方案1】:

以下是示例:

有效

FOOB45-9876
BAZZ36-1726

无效

foob47-8372 // may not contain lowercase letters
FOO36-8373  // only 3 starting characters
FOOB29_8473 // underscore instead of hyphen
FOOBa3-8272 // must contain two numbers before the hyphen

等等。

正如@Petru Gardea 评论的那样,XSD 的正则表达式风格隐含地锚定为 ^ 和 $,这意味着 FFOOB45-9876FOOB45-98767 都将无效,而所有其他正则表达式引擎(我们知道)实际上会匹配它们。

【讨论】:

  • 我要补充一点,XSD 的正则表达式风格隐式地使用 ^ 和 $ 锚定,这意味着 FFOOB45-9876 和 FOOB45-98767 都是无效的,而所有其他正则表达式引擎(我知道)实际上会匹配他们。
  • 感谢@PetruGardea,将其添加到答案中!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
  • 2021-04-25
  • 1970-01-01
  • 2018-04-02
  • 1970-01-01
相关资源
最近更新 更多