[netmod] Potential additions to rfc6087bis: RegEx guidelines

Xufeng Liu <Xufeng_Liu@jabil.com> Wed, 23 August 2017 21:20 UTC

Return-Path: <Xufeng_Liu@jabil.com>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id CB04B132714 for <netmod@ietfa.amsl.com>; Wed, 23 Aug 2017 14:20:42 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.909
X-Spam-Level:
X-Spam-Status: No, score=-2.909 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=jabil.onmicrosoft.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bDYXUVdppbo9 for <netmod@ietfa.amsl.com>; Wed, 23 Aug 2017 14:20:39 -0700 (PDT)
Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0124.outbound.protection.outlook.com [104.47.34.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id EB0B21329E4 for <netmod@ietf.org>; Wed, 23 Aug 2017 14:20:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jabil.onmicrosoft.com; s=selector1-jabil-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PQSp5+/MwFkbHuhxTdOy5aQRi19HDXjI0gZn77MqrrY=; b=VDmDe1iHj/BKeQdorv37APx1fBnhgh28ohoVQbTNMR5X8YNE1fAmeB0RBWwErI8iFRQLxavx5KC29wy2xngTQLhEjKU9EeZEro7Tdlq+ofczpFxcIg4ev50+74rs9Kb3AB5ISKlXOzk5syc1uq60sqaGZl57LqyM7N0dt+VxQTs=
Received: from BN3PR0201MB0867.namprd02.prod.outlook.com (10.160.154.13) by BN3PR0201MB0932.namprd02.prod.outlook.com (10.160.155.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1385.9; Wed, 23 Aug 2017 21:20:36 +0000
Received: from BN3PR0201MB0867.namprd02.prod.outlook.com ([10.160.154.13]) by BN3PR0201MB0867.namprd02.prod.outlook.com ([10.160.154.13]) with mapi id 15.01.1362.019; Wed, 23 Aug 2017 21:20:36 +0000
From: Xufeng Liu <Xufeng_Liu@jabil.com>
To: "'netmod@ietf.org'" <netmod@ietf.org>
Thread-Topic: Potential additions to rfc6087bis: RegEx guidelines
Thread-Index: AdMcU4SqqeTEr3DWR4ygcD75zJMNgA==
Date: Wed, 23 Aug 2017 21:20:36 +0000
Message-ID: <BN3PR0201MB0867DAD1212DBA2E88570AD5F1850@BN3PR0201MB0867.namprd02.prod.outlook.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-dg-ref: PG1ldGE+PGF0IG5tPSJib2R5Lmh0bWwiIHA9ImM6XHVzZXJzXHhsaXVcYXBwZGF0YVxyb2FtaW5nXDA5ZDg0OWI2LTMyZDMtNGE0MC04NWVlLTZiODRiYTI5ZTM1Ylxtc2dzXG1zZy1lNWM0ZWVkOC04ODQ4LTExZTctOWMyOC0xODVlMGZlM2M0NWNcYW1lLXRlc3RcZTVjNGVlZDktODg0OC0xMWU3LTljMjgtMTg1ZTBmZTNjNDVjYm9keS5odG1sIiBzej0iMjEyNDgiIHQ9IjEzMTQ3OTk2ODM0NzgyMDI2NiIgaD0iamc4QWxOdmRjSmdsckwxL1dJNE1oWVkrMjNjPSIgaWQ9IiIgYmw9IjAiIGJvPSIxIi8+PC9tZXRhPg==
x-dg-tag-bcast:
x-dg-paste:
x-originating-ip: [98.191.72.170]
x-ms-publictraffictype: Email
x-microsoft-exchange-diagnostics: 1; BN3PR0201MB0932; 6:1KgptufSJ5toU2QTGFzy9zqAnU/dgfv53S54bNINHADMU1TqSs0821f5fdHRaEFjycAlIIqzM5A+5pEj0hrl5a/LztXCj9DqPOOYQsdnm54H2zLf0XqNmv877ntkSF4tckxCweVW9rIXyzvIj5Q7yWvm6WbsnPa93CVQVDfSlZEpV7bhj9HQeRUUQKknc0n3DvJZ/lbUclDZm0rke59SsX4mbsaTwfNpJeV/geW/7jzGxT48/JQSDJTkNQIuTxCC+fAbCcO8sVM1pv0AIZ4ANxax5UFQoyUyTA9//XfxlIr2W37sJWX3qCqckemGlYoLiUqBf2Ct/VTabjxwvkSuVA==; 5:aZ4zjsnXgFFttnCGpQbOAbn0scI+DOJA2D6FfCXKgVQhvAndcBzV1rhvG20cYtR8+PBmFExIfkO2vLBze+SkGqvc7NHO1GCxvuSS/3uI3/zMaHVcK4nUfI0HSgwc432teX+NG9jNy8xXo5zrPSmzXA==; 24:N1DqJgsPWgyUaQmgKHhX0xNPNjma0FyMB6Az02z58LVHf0JOqhThsi7Ne6k2/n7eEUqUc1shtI9viiR+B383KSoFi2Skj+d2MaCYQH8nZbY=; 7:FLCry9u0LymFL7CF+MHYJNgaFfjR9MdiL2CcqUtsK/4tszTpF7Uu2Hx0JWuu/6ukezQMt11SX3k1A6po2BT1Xe1NYYVZWlLRLem4Ik1YvijLPLq+90II/4FRFudufpB5e1edRKvJ67BU5gGILyho0Q5fP/3nBJEFJKa2MEFPc8MBkveG5sbFc7rAxZvpG55hfJi1jJljvpPIHLB812nhCNcLWBJYcTH9/QRKT9E9HFo=
x-ms-exchange-antispam-srfa-diagnostics: SSOS;
x-ms-office365-filtering-correlation-id: 10cd7614-b823-4b80-3768-08d4ea6ccc1b
x-ms-office365-filtering-ht: Tenant
x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603189)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:BN3PR0201MB0932;
x-ms-traffictypediagnostic: BN3PR0201MB0932:
x-exchange-antispam-report-test: UriScan:(166708455590820)(21748063052155);
x-microsoft-antispam-prvs: <BN3PR0201MB093299746484F219B932574AF1850@BN3PR0201MB0932.namprd02.prod.outlook.com>
x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BN3PR0201MB0932; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BN3PR0201MB0932;
x-forefront-prvs: 040866B734
x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(39860400002)(189002)(199003)(7696004)(966005)(478600001)(33656002)(72206003)(6916009)(189998001)(68736007)(101416001)(6116002)(3846002)(790700001)(74316002)(5660300001)(50986999)(66066001)(54356999)(86362001)(105586002)(8936002)(106356001)(55016002)(110136004)(99286003)(102836003)(2900100001)(6306002)(54896002)(3280700002)(3660700001)(9686003)(25786009)(7736002)(81166006)(81156014)(8676002)(6436002)(77096006)(97736004)(6506006)(2906002)(14454004)(80792005)(53936002)(491001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR0201MB0932; H:BN3PR0201MB0867.namprd02.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en;
received-spf: None (protection.outlook.com: jabil.com does not designate permitted sender hosts)
authentication-results: spf=none (sender IP is ) smtp.mailfrom=Xufeng_Liu@jabil.com;
spamdiagnosticoutput: 1:99
spamdiagnosticmetadata: NSPM
Content-Type: multipart/alternative; boundary="_000_BN3PR0201MB0867DAD1212DBA2E88570AD5F1850BN3PR0201MB0867_"
MIME-Version: 1.0
X-OriginatorOrg: jabil.com
X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Aug 2017 21:20:36.7160 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: bc876b21-f134-4c12-a265-8ed26b7f0f3b
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0201MB0932
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/l1IsakACWW2ODwVKwGxHg6SmKIQ>
Subject: [netmod] Potential additions to rfc6087bis: RegEx guidelines
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.22
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 23 Aug 2017 21:20:43 -0000

Members of Routing Area Yang DT have had some discussions about the handling of various variants of regular expressions. The followings are the current state, and we are thinking that if this topic can be added to RFC6087bis:

1. Regular Expression Usage
YANG uses regular expressions to restrict string values. Such a restriction can be a part of a "pattern" statement or a string matching function. [RFC7950] specifies that YANG regular expressions will conform to Appendix F in [XSD-TYPES].
YANG models have been implemented in many different environments and the XSD variant of the regular expressions is not supported in many of these environments. There are currently more than a dozen popular regular expression variants implemented in various environments. While the usage of the XSD variant of regular expression described in [RFC7950] remains the preferred standard, a few conventions are prescribed to maximize the portability of YANG models between environments.

1.1. Regular Expression Variant Choice Precedence
YANG model designers SHOULD use the most portable syntax whenever possible. Under the condition that XSD compliance is satisfied and there are multiple choices for a given expression, the following precedence SHOULD be used to choose a regular expressions variant:

o    POSIX base

o    POSIX extended

o    BSD

o    GNU Regular Expression Extensions

o    C++ Regular Expressions with std::regex

o    Others

For example, either \d or [0-9] can be used with equivalent semantics and they are both compliant to [XSD-TYPES]. [0-9] is recommended because [0-9] is supported by POSIX base but \d is not.

1.2.  Convention Guidelines
1.2.1. Avoid Character Category Escapes
For example, in XSD regular expression, \d is a Character Category Escape denoting the range of digits, i.e.,  [0-9]. To maximize portability, the model designers SHOULD use [0-9] instead of \d.

1.2.2. Avoid Unicode Characters
Unicode characters are allowed in XSD regular expressions, but are not supported in the POSIX variant. If possible, the model designers SHOULD avoid using Unicode characters, such as: \p{L} and \p{N}.

1.3. Conversion Tools
Tools can automatically convert regular expressions from one variant to another. When a YANG model is implemented in an environment where XSD regular expressions are not supported, the recommended approach is to use a conversion tool. For example, if needed, anchor position characters, i.e., '^' and '$', can be added by a regular expression conversion tool.

1.4. Validation Tools
Tools can be used to validate regular expressions in YANG files. The followings are some of these tools:

o    YANG W3C Regex Expression Validator: https://yangcatalog.org/yangre

This an on-line tool with a WEB interface.

o    yangre as a part of the libyang package:
https://github.com/CESNET/libyang

This is an open source tool with a command line interface.

Usage:

    yangre [-hvV] -p <regexp1> [-i] [-p <regexp2> [-i] ...] <string>



Returns 0 if string matches the pattern(s), 1 if not and -1 on error.



Options:

  -h, --help              Show this help message and exit.

  -v, --version           Show version number and exit.

  -V, --verbose           Print the processing information.

  -i, --invert-match      Invert-match modifier for the closest preceeding

                          pattern.

  -p, --pattern="REGEXP"  Regular expression including the quoting,

                          which is applied the same way as in a YANG module.



Examples:

  pattern "[0-9a-fA-F]*";      -> yangre -p '"[0-9a-fA-F]*"' '1F'

  pattern '[a-zA-Z0-9\-_.]*';  -> yangre -p "'[a-zA-Z0-9\-_.]*'" 'a-b'

  pattern [xX][mM][lL].*;      -> yangre -p '[xX][mM][lL].*' 'xml-encoding'



References



[XSD-TYPES] Biron, P. and A. Malhotra, "XML Schema Part 2: Datatypes Second Edition", World Wide Web Consortium Recommendation REC-xmlschema-2-20041028, October 2004, <http://www.w3.org/TR/2004/REC-xmlschema-2-20041028>

[POSIX]   IEEE Std 1003.1-2008, 2016, <https://standards.ieee.org/findstds/standard/1003.1-2008.html>

[BSD]     Regular Expression, <http://www.bsd.org/regexintro.html>

[C++]     ISO/IEC DIS 14882: Programming Languages - C++, 2017.

Thanks,
- Xufeng