Yang pattern does not accept valid Regex when it contains caret ^ or dollar $.
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.
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.
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:
If you follow the normative reference
XSD-TYPES
, you eventually get to: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).
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. 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.