YANG patteren to allow string which does not contain repetitive zero?

I want to allow a string which does not contain leading zeros in an interface name string,
i.e :- GigabitEther 002 --> invalid
GigabitEther 0/0/03 --> invalid
GigabitEther 0 --> valid

how it can be done using YANG pattern ?

(0|[1-9][0-9]*)(/(0|[1-9][0-9]*))* - repetitions of single zero or non-zero-initiated numbers separated by slashes. Is that what you are looking for?

1 Like

Thanks for your response!!
Yes i was looking something like this only, added to this sub interface name will have ’ . ’ also with them. So final pattern is like this

list GigabitEthernet {
key "name";
leaf name {
   type string {
      pattern "(0|[1-9][0-9]*)(/(0|[1-9][0-9]*))*(.[0-9]*)?";

But even this is not rejecting the incorrect string values

interface GigabitEthernet 002 is also a pass case after this :frowning:

Need Further help!!

Keep in mind that dot (".") is a special character that matches any character, in particular including zero. So your addition should be (\\.[0-9]*)? - this way you are saying that the dot should be interpreted literally.