ConfD User Community

Nested brackets in yang pattern

(((([)[(^)0-9,A-F#.?+%()-]+(])|[(^)0-9,A-F#.?+%()-])*T?($)?))
this pattern will not accept open square bracket separately ([) and close square brackets separately (]).
However when used together like this [12][213] with some characters in between it accepts. But with this i should also accept nested brackets to [90][212[12]212] too. Is this possible in yang?
Note: [] - should NOT be accepted
2122212[ - should NOT be accepted
129] not be accepted
the parenthesis should get matched and some characters should be present in between it…
Please help

If you need to support arbitrarily deep bracketed expression nesting, you cannot do that. In YANG patterns can be defined using “W3C regular expressions”, which are just basic regular expressions with some syntactic sugar added, and in regular expressions you cannot verify stuff like balanced parentheses.

Many regular expression implementations add fancy stuff like balancing groups or recursive patterns that can be used for this kind of syntax check, but none of these is available for YANG patterns. I believe your only option, if you need to have this check already at the value level, are ConfD user types - have a look at misc/user_types example in the ConfD distribution.