Escaped dot character in pattern

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?

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

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]*";
    }
  }

Yes. This should be same. First one is more convenient if your expression string does not contain any '.

One last question: am I allowed to explicitly mark the beginning (^) and end ($) of strings in a patter, as in a regular regex?

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