-1

I need to give some limited possibilities for an Attribute in xml, for this I am using in Relax NG validation document:

<param "pattern">myRegEx</param>

allowing to specify some regular expression the attribute need to be conform to.

For some reason pattern does not support use of $ (end-of-string) sign.

Example:

<param "pattern">Why it does not work??$</param>

This is supposed to match to string ending with "Why it does not work??" sentence. But the $ seems to be totally ignored from the validation.

Does anyone understand why?

thank you

Nathaniel

4

1 回答 1

1

RNG 'pattern' 参数与 XSD 简单类型定义上的模式构面具有相​​同的*语义。XSD 模式适用于被验证的整个词法项——XSD 模式没有用 ^ 和 $ 作为字符串开始和字符串结束的锚点,因为 XSD 模式总是匹配整个输入字符串或不匹配。(对于假设所有正则表达式语言都有 ^ 和 $ 如果 XSD 指定它们在模式的开头和结尾被忽略的人可能会更好,但这并没有发生。)

如果您想定义一个匹配任何以字符串“Why does it not work??”结尾的文本节点的模式,而不是匹配两个字符串“Why does it not work$”或“Why does it not wor”中的任何一个$",你会想写

<param name="pattern">.*Why does it not work\?\?</param>

笔记:

  • 失去$
  • 逃脱?

(* 多模式的处理有一个无缘无故的不兼容,但在这里不相关。)

于 2014-08-19T15:48:07.677 回答