正则表达式,xsd 中的模式匹配 [英] Regular Expression, pattern matching in xsd
问题描述
我想知道如何为除 *
和 +
之外的任何字符制作正则表达式.我试过 ([^*+])
和 (\[^*+])
但两个表达式似乎都不正确.有人可以指出我正确的方向吗?谢谢.
I was wondering how to make a regular expression for any character except *
and +
. I've tried ([^*+])
and (\[^*+])
but both expressions seem to be incorrect. Can someone please point me in the right direction? Thanks.
这是一个代码片段.我已将下面建议的 reg ex 附加到 Visual Studio 中,当我输入常规字符串时,它仍然会生成错误.
Here is a code snipet. I've attached the reg ex suggested below into visual studio and it still generates an error when i enter in a regular string.
<xsd:element name="elementName">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="/^[^*+]+$/"></xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
我使用的示例字符串是test"结果是模式约束失败,当前正则表达式:/^[^*+]+$/
The example string I'm using is "test"
The result is pattern constraint fail with the current reg ex: /^[^*+]+$/
推荐答案
在 XML Schema regex flavor 中,您不得添加正则表达式分隔符(即 /^[^*+]+$/
两端的 /
).您也不需要使用锚点(即开头的 ^
和结尾的 $
);所有正则表达式匹配都会自动锚定在两端.该行应为:
In the XML Schema regex flavor, you must not add regex delimiters (i.e., the /
at either end of /^[^*+]+$/
). You also don't need to use anchors (i.e., the ^
at the beginning and $
at the end); all regex matches are automatically anchored at both ends. That line should read:
<xsd:pattern value="[^*+]+"></xsd:pattern>
...意味着整个元素必须由一个或多个除了 *
和 +
之外的任何字符组成.
...meaning the whole element must consist of one or more of any characters except *
and +
.
这篇关于正则表达式,xsd 中的模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!