0

I want to have "YANG" regex expression inputting a string of the format

"c[space or consecutive spaces][character string][space or consecutive spaces]c"

Please let me know the yang regex for this. Please suggest only the "yang" expressions.

example:

       "cabdc"

     "c    ab    c"
Darshan b
  • 157
  • 7
  • Your question is unclear. If you are looking for a regular expression that matches your examples, `[cabd ]+` would be one of the many possibilities. [This answer](https://stackoverflow.com/a/49188838/878469) contains more info on YANG regular expressions. – predi Jun 20 '19 at 06:42
  • @predi i have updated the format. – Darshan b Jun 20 '19 at 07:03
  • `pattern 'c[ ]*[a-zA-Z]+[ ]*c';`. I suggest you read more about regular expressions in general. – predi Jun 20 '19 at 11:21
  • @predi The suggested expression does not work in yang. – Darshan b Jun 21 '19 at 09:27
  • Yes, it does. Why to you think it does not, @Darshan? – predi Jun 21 '19 at 10:27
  • @predi tried the mentioned suggestion and it gave me a compile error of bad pattern – Darshan b Jun 24 '19 at 04:37
  • your compiler is wrong. You can double check [here](http://www.utilities-online.info/xsdvalidation/) by pasting `cabdc` into left field and ` ` into the right one. Since YANG uses XSD regexes, if it is valid there, it is valid in YANG. – predi Jun 26 '19 at 06:23

1 Answers1

0

The regular expressions used in yang are similar to the general regular expressions. The keyword in yang for a regex is "pattern".

General example -

type xyz {
       pattern '[a-zA-Z0-9]{1,128}';
}

As for your question, the answer would be -

pattern 'c[ ]{1,}[a-zA-Z]{1,}[ ]{1,}c';