Regex to filter '*' and '?' special character in yang model

微笑、不失礼 提交于 2019-12-13 02:59:44

问题


I am trying to create a regex in yang model to not allow * and ? characters. String * and ? should not be allowed as input. .e.g. - abc* - should be okay - * - is not okay and should be rejected Similarly string ("?") should be rejected. Tried my hand with regex '[^?]+' which is rejecting any string with any occurrence of * and ?. .e.g abc*, *abc, * and ? all of them are rejected.


回答1:


YANG uses the XML Schema (XSD) flavor of regular expressions, but this case would be similar in most flavors. If I understand correctly, you wish to prohibit a string to start with characters * and ?.

[^*?].*

The above says: the string always has at least one character, where the first character may be any character except * or ? and may be followed by any number of arbitrary characters.

You can read more about the specifics of YANG regular expressions here. Do note that there are subtle differences between regexes defined in different versions of XSD Schema and that YANG relies on the one defined in normative references section of RFC7950 (and RFC6020).



来源:https://stackoverflow.com/questions/49172056/regex-to-filter-and-special-character-in-yang-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!