
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 08:39 AM - edited 03-01-2019 03:52 AM
Hi Team,
So far, I used the following pattern in the yang "[a-z0-9 -] *" for per example matching this string : switch01-dev001
Now, i'm looking for matching also forward slash /
i changed the pattern to "[a-z0-9-/]*" but i doesn't work. I would like to match the following string : switch01-dev/001
Do you have an idea ?
Regards,
Yannick
Solved! Go to Solution.
- Labels:
-
Other NSO Topics
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 05:36 AM
You could use [a-z0-9/-]*
Placing the dash last within the brackets is a 40-year old trick. That ensures it's not treated as part of any character range.
/jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 09:04 AM
Hi Yannick,
maybe you have to precede it with the backslash: "[a-z0-9-\/]*"
Best Regards
Christian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 09:22 AM
Hi Christian,
Thanks, I tried "[a-z0-9-\/]*"
But i have this ouput after a make :
.yang:22: error: invalid pattern: "Bad Pattern"
.yang:22:20: warning: illegal character after \
Best Regards,
Yannick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 10:39 AM
Hello Yannick,
I think solution here is to escape "-" instead of "/".
Without "-", it looks pattern is working with forward slash.
leaf dummy {
type string {
pattern "[a-z0-9/]+";
}
}
admin@ncs(config)# ytest test dummy dev/001
admin@ncs(config-ytest-test)#
If I add "-", it fails because "-" means a range.
type string {
pattern "[a-z0-9-/]+";
}
admin@ncs(config)# ytest test dummy switch01-dev/001
------------------------------------^
syntax error: "switch01-dev/001" is an invalid value.
admin@ncs(config)#
So, if I escape "-" then it works.
type string {
pattern "[a-z0-9\-/]+";
}
admin@ncs(config)# ytest test dummy switch01-dev/001
admin@ncs(config-ytest-test)#
By the way, I prefer using "-" outside of [] such as follows.
type string {
pattern "[a-z0-9]+\-dev/[0-9]+";
}
Hope this helps.
Best regards,
Hiro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 10:50 AM
Thank you Hiro,
you're right!
"-" is a special character inside the square brackets. Outside it is not.
It should work also in this way: "[a-z0-9]+-dev/[0-9]+" or more generic: "[a-z0-9]+-*/*"
Let me know.
Best Regards
Christian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 11:00 AM
Hello Christian,
Indeed, "-" should work without escaping outside of square brackets as "[a-z0-9]+-dev/[0-9]+".
Thank you for the correction!
Best regards,
Hiro

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 12:31 AM
Hi guys,
Thanks a lot, you have helped me to better understand the structure.
My final generic pattern is : "[a-z0-9]*-*/*";
Best regards,
Yannick

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2017 05:36 AM
You could use [a-z0-9/-]*
Placing the dash last within the brackets is a 40-year old trick. That ensures it's not treated as part of any character range.
/jan
