Skip to content

regex pattern matching issue in devel branch #2493

Open

Description

@srikanthsubbaramu

Hi Michal,

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?

Thanks,
srikanth

Activity

  1. jktjkt commented on Mar 9, 2026

    @jktjkt
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:questionIssue is actually a question.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions