rick_r
October 17, 2017, 9:02am
1
I’d like to have a regular expression matching the dot character, but it seems that escaping it won’t work.
typedef my-str {
type string {
pattern "\.[a-zA-Z]*";
}
}
confd 6.4.3 won’t compile:
my.yang:98:16: error: illegal character after \
According to the documentation (Section 16.6.5), the dot character alone matches any character, as expected in a regular expression.
Is this a bug or should I escape the dot in a different way?
mnovak
October 17, 2017, 11:50am
2
It is probably same/similar to Tailf:dependency "."; is deprecated in confd 6.4.3? .
If yes, the solution is to use '
instead of "
of use double backslash \\
.
In YANG 1.1, it is illegal to have any character except ‘n’ ‘t’ ‘"’ or ‘’ immediately after the backslash.
1 Like
rick_r
October 17, 2017, 1:10pm
3
Thanks!
So it’s either the same pattern within single quotation marks:
typedef my-str {
type string {
pattern '\.[a-zA-Z]*';
}
}
… or a double backslash instead of a simple backslash with the pattern within double quotation marks:
typedef my-str {
type string {
pattern "\\.[a-zA-Z]*";
}
}
mnovak
October 18, 2017, 11:53am
4
Yes. This should be same. First one is more convenient if your expression string does not contain any '
.
rick_r
October 18, 2017, 1:34pm
5
One last question: am I allowed to explicitly mark the beginning (^) and end ($) of strings in a patter, as in a regular regex?
cohult
October 18, 2017, 6:50pm
6
YANG uses the XSD-dialect of regular expressions (see section 9.4.5 of RFC 7950 ). This dialect does NOT support ^ and $ as anchors. The expression is implicitly anchored at the beginning and end