gpt4 book ai didi

regex - XSD 正则表达式模式 : this or nothing

转载 作者:行者123 更新时间:2023-12-04 13:29:24 24 4
gpt4 key购买 nike

我正在尝试在 XSD 中定义一个方案规则,其字符串长度为 8 个字符:

<PostedDate>42183296</PostedDate>

也允许空间填充:
<PostedDate>        </PostedDate>

这让我想到了 XSD:
<xs:simpleType name="DateFormat">
<xs:restriction base="xs:string">
<xs:length value="8" /> //exactly 8 characters long
</xs:simpleType>

但值 可以 也为空(即零个字符长):
<PostedDate></PostedDate>
<PostedDate />

这让我天真地尝试:
<xs:simpleType name="DateFormat">
<xs:restriction base="xs:string">
<xs:length value="8" /> //exactly 8 characters long
<xs:length value="0" /> //exactly 0 characters long
</xs:simpleType>

这当然是不允许的。

与 XSD 中的情况一样,大多数格式无法用 XSD 轻松表示,因此我选择尝试使用正则表达式规则:
.{8} | ""

试图转换为 XSD 我输入:
<xs:simpleType name="DateFormat">
<xs:restriction base="xs:string">
<xs:pattern value=".{8}|''" />
</xs:restriction>
</xs:simpleType>

但它没有用:
''20101111' is not facet-valid with respect to pattern '.{8}|''' for type 'DateFormat'

我也试过
  • <xs:pattern value="[0-9]{8}|''" />
  • <xs:pattern value="([0-9]{8})|('')" />
  • <xs:pattern value="(\d{8})|('')" />

  • 其他任何人都可以解决匹配问题的模式吗
    - 一些特定的模式
    - 空的

    奖金:谁能指出 the XSD documentation中的那个地方那就是 \d匹配数字?或者其他特殊的模式代码是什么?

    最佳答案

    我可能猜想模式应该看起来像 \d{8}|这意味着“八位数字或没有”,但不是八位数字或两个引号。然而这并不能解释为什么20101111不匹配。您确定元素值中没有空格或其他附加符号吗?\d据说匹配“F.1.1 字符类转义”部分中的数字

    关于regex - XSD 正则表达式模式 : this or nothing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4227422/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com