Yang regular expression for digit validation

280 views Asked by At

Need to update a leaf with regular expression in Yang...

Basically it should take only digits and ranges from 1-32

valid patters are:

1,2,3,4-7,22-30,32,31 - valid

1,2,3,4-7,22-30,32,31,1-10 - invalid as some are overlapping with other

33,45,33-45,3345 - invalid

tried with below code, but is there way to add range to this and remove overlaps from expression...

(([1-9][1-9]?|([1-9][1-9]?-[1-9][1-9]?))(,([1-9][1-9]?|([1-9][1-9]?-[1-9][1-9]?)))*)

1

There are 1 answers

1
Nick Reed On

No, this is not possible. Regex alone is not strong enough to detect overlaps in numerical sets. If you want to use regex to validate your input set and then check it programmatically, however, that's more than possible. The following pattern will match the inputs your question has asked for:

(?:\d+(?:-\d+)?,?)+ (Demo)

Actually validating there's no overlap present is up to your program.