Home

Awesome

<!--#region:intro-->

Regular Expression Pattern Modifiers for ECMAScript

<!--#endregion:intro--> <!--#region:status-->

Status

Stage: 3
Champion: Ron Buckton (@rbuckton)

For detailed status of this proposal see TODO, below.

<!--#endregion:status--> <!--#region:authors-->

Authors

<!--#endregion:authors--> <!--#region:motivations-->

Motivations

One common capability amongst the majority of regular expression engines that is commonly used by parsers, syntax highlighters, and other tools is the capability to control a subset of regular expression flags such as:

Modifiers are especially helpful when regular expressions are defined in a context where executable code cannot be evaluated, such as a JSON configuration file or TextMate tmLanguage grammar file.

As part of this proposal, we will investigate each existing (and future-proposed) RegExp flag to determine whether they are feasible to used as modifiers.

<!--#endregion:motivations--> <!--#region:prior-art-->

Prior Art

See https://rbuckton.github.io/regexp-features/features/modifiers.html for additional information.

<!--#endregion:prior-art--> <!--#region:syntax-->

Syntax

Modifiers allow you to change the currently active RegExp flags within a subexpression.

NOTE: Certain flags cannot be modified mid-expression. These currently include g (global), y (sticky), u (unicode), and d (hasIndices).

NOTE: The actual supported flags will be determined on a case-by-case basis. See #1.

NOTE: This has no conflicts with existing syntax, as ECMAScript currently produces an error for this syntax in both u and non-u modes.

NOTE: The "self-bounded" form ((?imsx-imsx:subexpression)) advanced to Stage 2 on December 15th, 2021.

NOTE: The "unbounded" form ((?imsx-imsx)) is no longer being considered as part of this proposal as of December 15th, 2021.

<!--#endregion:syntax--> <!--#region:semantics--> <!-- # Semantics --> <!--#endregion:semantics--> <!--#region:examples-->

Examples

const re1 = /^[a-z](?-i:[a-z])$/i;
re1.test("ab"); // true
re1.test("Ab"); // true
re1.test("aB"); // false

const re2 = /^(?i:[a-z])[a-z]$/;
re2.test("ab"); // true
re2.test("Ab"); // true
re2.test("aB"); // false
<!--#endregion:examples--> <!--#region:api--> <!-- # API > TODO: Provide description of High-level API. --> <!--#endregion:api--> <!--#region:grammar--> <!-- # Grammar ```grammarkdown ``` --> <!--#endregion:grammar--> <!--#region:references--> <!-- # References > TODO: Provide links to other specifications, etc. * [Title](url) --> <!--#endregion:references-->

History

<!--#region:todo-->

TODO

The following is a high-level list of tasks to progress through each stage of the TC39 proposal process:

Stage 1 Entrance Criteria

Stage 2 Entrance Criteria

Stage 3 Entrance Criteria

Stage 4 Entrance Criteria

<!--#endregion:todo--> <!-- The following links are used throughout the README: -->