You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
regex pattern matching issue in devel branch #2493
we are using devel branches of libyang/netconf2/sysrepo/netopeer2
file:
_3gpp-common-yang-types.yang
typedef Nid {
description "This represents the Network Identifier, which
together with a PLMN ID is used to identify a SNPN.";
type string {
pattern '^[A-Fa-f0-9]{11}$';
}
reference "3GPP TS 23.003 and 3GPP TS 23.501 clause 5.3.2.1.";
}
leaf-list nIDList {
type Nid;
max-elements 16;
description "It identifies a list of NIDs containing up to 16 NIDs, see
TS 38.331. NID is used to combine with PLMN ID to identify an SNPN.
NID is a hexadecimal range with size 44 bit.";
}
when we try to use above data with data for Nid
ABCDEFABCDE
we see below failure in netopeer2 from libyang
[2026-03-09 19:03:03.618077] [ERR]: SR: Unsatisfied pattern - "ABCDEFABCDE" does not match "^[A-Fa-f0-9]{11}$". (path "/_3gpp-common-managed-element:ManagedElement/_3gpp-nr-nrm-gnbcuupfunction:GNBCUUPFunction/_ran-nr-nrm-gnbcuupfunction:nPNIdentityList/nIDList")
when we changed the definition of Nid to remove ^ $, the pattern matching worked,
typedef Nid {
description "This represents the Network Identifier, which
together with a PLMN ID is used to identify a SNPN.";
type string {
pattern '[A-Fa-f0-9]{11}';
}
reference "3GPP TS 23.003 and 3GPP TS 23.501 clause 5.3.2.1.";
}
is this expected or should symbols in regex ^$ should work?
The pattern statement uses regex syntax from the XML schema, where the regular expressions are implicitly anchored:
Note: Unlike some popular regular expression languages (including those defined by Perl and standard Unix utilities), the regular expression language defined here implicitly anchors all regular expressions at the head and tail, as the most common use of regular expressions in ·pattern· is to match entire literals.
In the OpenConfig world, YANG models are written in an incompatible way where the patterns are not implicitly anchored. If an OpenConfig model is parsed by a compliant YANG implementation, these patterns will no longer match properly. In the most recent version of libyang, support for the openconfig-extensions:posix-pattern extension was added, so if you tag your YANG model appropriately, it should work as you expect.
Activity
jktjkt commentedon Mar 9, 2026
The
patternstatement uses regex syntax from the XML schema, where the regular expressions are implicitly anchored:In the OpenConfig world, YANG models are written in an incompatible way where the patterns are not implicitly anchored. If an OpenConfig model is parsed by a compliant YANG implementation, these patterns will no longer match properly. In the most recent version of libyang, support for the
openconfig-extensions:posix-patternextension was added, so if you tag your YANG model appropriately, it should work as you expect.