简体   繁体   English

杨模式不接受包含 ^ 和 $ 的正则表达式

[英]Yang pattern not accepting regex containing ^ and $

Yang pattern does not accept valid Regex when it contains caret ^ or dollar $.当 Yang 模式包含插入符号 ^ 或美元 $ 时,它不接受有效的正则表达式。

The bellow pattern is valid on Regex validators, but when run inside a Yang pattern template in an is-types.yang file my application errors.波纹管模式在正则表达式验证器上有效,但是当在 is-types.yang 文件中的杨模式模板内运行时,我的应用程序错误。

However when i take off the ^ and $ from each part of the expression it works fine.但是,当我从表达式的每个部分中删除 ^ 和 $ 时,它可以正常工作。 However this now allows the regex to accept unwanted values.但是,这现在允许正则表达式接受不需要的值。

I am trying to match either 1, 11, 1/1/1, 1/1/1/1.我正在尝试匹配 1、11、1/1/1、1/1/1/1。

Trying the pattern:尝试模式:

^([0-9]{1,3}/[0-9]{1,3}/[0-9]{1,3})$|^([0-9]{1,3}/[0-9]{1,3}/[0-9]{1,3}/[0-9]{1,3})$|^([0-9]{1,2})$

Yang typedef:杨类型定义:

typedef interface_number_value {
    type string {
        pattern "([0-9]{1,3}/[0-9]{1,3}/[0-9]{1,3})|([0-9]{1,3}/[0-9]{1,3}/[0-9]{1,3}/[0-9]{1,3})|([0-9]{1,2})" {
            error-message "error";
        }
    } 
    description
        "description";
}

Also I am not sure where to raise issues/bugs with Yang.我也不确定在哪里向杨提出问题/错误。

This is what RFC7950 says about the "pattern" statement:这就是 RFC7950 关于“模式”声明的内容:

The "pattern" statement, which is an optional substatement to the "type" statement, takes as an argument a regular expression string, as defined in [XSD-TYPES]. “pattern”语句是“type”语句的可选子语句,将正则表达式字符串作为参数,如 [XSD-TYPES] 中定义的那样。 It is used to restrict the built-in type "string", or types derived from "string", to values that match the pattern.它用于将内置类型“string”或从“string”派生的类型限制为与模式匹配的值。

If you follow the normative reference XSD-TYPES , you eventually get to:如果您遵循规范性参考XSD-TYPES ,您最终会得到:

[XSD-TYPES] Biron, P. and A. Malhotra, "XML Schema Part 2: Datatypes Second Edition", World Wide Web Consortium Recommendation REC-xmlschema-2-20041028, October 2004, http://www.w3.org/TR/2004/REC-xmlschema-2-20041028 . [XSD-TYPES] Biron, P. 和 A. Malhotra,“XML 模式第 2 部分:数据类型第二版”,全球范围 Web 联盟建议 REC-xmlschema-2-20041028,2004 年 10 月, Z80791B3AE7002CB88C24://www876D9FAA8F8。 /TR/2004/REC-xmlschema-2-20041028

Therefore the regular expressions in YANG "pattern" statements are defined by XML Schema (XSD) type specs (and that specific revision of them for YANG 1.0 and 1.1).因此,YANG“模式”语句中的正则表达式由 XML Schema (XSD) 类型规范(以及针对 YANG 1.0 和 1.1 的特定修订版)定义。

Unlike some other regex flavors, a ^ character at the beginning of a YANG "pattern" or a $ at the end of a YANG "pattern" are not interpreted as anchors.与其他一些正则表达式不同,YANG“模式”开头的^字符或 YANG“模式”结尾的$不会被解释为锚点。 Instead they are interpreted literally as characters that must match.相反,它们被逐字解释为必须匹配的字符。 All "pattern" expressions are implicitly anchored and therefore match the entire value.所有“模式”表达式都是隐式锚定的,因此匹配整个值。

You can find out more about the specifics of XML Schema Regular Expressions here .您可以在此处找到有关 XML 模式正则表达式的详细信息的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以接受正则表达式范围内的特殊字符? - Is accepting special characters for a range within a regex pattern possible? 设置不接受某些特定符号的字母数字正则表达式模式 - Set alphanumeric regex pattern not accepting certain specific symbols 正则表达式:包含模式的字符数 - Regex expression: number of characters containing a pattern 如何匹配包含特定模式的段落与正则表达式? - How to match paragraphs containing a specific pattern with regex? Python 正则表达式:提取包含小数的系列中的多个模式 - Python regex : extract multiple pattern in series containing decimal 正则表达式从元组列表中捕获包含特定模式的元组 - Regex to capture a tuple containing a particular pattern from a list of tuples 正则表达式:在任何地方接受空间,但在开始时 - Regex: Accepting space anywhere but at the beginning Python 通过接受 5 位数字作为输入进行图案打印 - Python Pattern Printing by accepting 5 Digit number as input 正则表达式:搜索包含4的字符串- - Regex: Search for string containing 4 - 如何使用包含反向引用'\\ 1'的字符串变量作为正则表达式模式,用于将ipa符号转换为类似arpabet的系统 - how to use string variable containing back-reference '\1' as regex pattern for converting ipa symbols to arpabet-like system
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM