{"id":13812742,"url":"https://github.com/tc39/proposal-regexp-buffer-boundaries","last_synced_at":"2025-04-19T17:34:34.289Z","repository":{"id":39672381,"uuid":"417634087","full_name":"tc39/proposal-regexp-buffer-boundaries","owner":"tc39","description":"Regular Expression Buffer Boundaries for ECMAScript","archived":false,"fork":false,"pushed_at":"2022-05-28T00:58:15.000Z","size":215,"stargazers_count":8,"open_issues_count":4,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-12T21:14:41.740Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tc39.es/proposal-regexp-buffer-boundaries","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tc39.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-15T20:58:47.000Z","updated_at":"2025-02-19T09:49:57.000Z","dependencies_parsed_at":"2022-09-20T07:50:56.439Z","dependency_job_id":null,"html_url":"https://github.com/tc39/proposal-regexp-buffer-boundaries","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-regexp-buffer-boundaries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-regexp-buffer-boundaries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-regexp-buffer-boundaries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-regexp-buffer-boundaries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tc39","download_url":"https://codeload.github.com/tc39/proposal-regexp-buffer-boundaries/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246174509,"owners_count":20735413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T04:00:55.013Z","updated_at":"2025-03-30T23:32:47.317Z","avatar_url":"https://github.com/tc39.png","language":"HTML","funding_links":[],"categories":["JavaScript regex evolution"],"sub_categories":["Regex processors, utilities, and more"],"readme":"\u003c!--#region:intro--\u003e\n# Regular Expression Buffer Boundaries for ECMAScript\n\nThis proposal seeks to introduce `\\A` and `\\z` character escapes to Unicode-mode regular expressions as synonyms for `^` and `$` that are not affected by the `m` (multiline) flag.\n\n\u003c!--#endregion:intro--\u003e\n\n\u003c!--#region:status--\u003e\n## Status\n\n**Stage:** 2  \n**Champion:** Ron Buckton ([@rbuckton](https://github.com/rbuckton))  \n\n_For detailed status of this proposal see [TODO](#todo), below._  \n\u003c!--#endregion:status--\u003e\n\n\u003c!--#region:authors--\u003e\n## Authors\n\n* Ron Buckton ([@rbuckton](https://github.com/rbuckton))  \n\u003c!--#endregion:authors--\u003e\n\n\u003c!--#region:motivations--\u003e\n# Motivations\n\n\u003e NOTE: See https://github.com/rbuckton/proposal-regexp-features for an overview of\n\u003e how this proposal fits into other possible future features for Regular Expressions.\n\nBuffer Boundaries are a common feature across a wide array of regular expression engines that \nallow you to match the start or end of the entire input regardless of whether the `m` (multiline) flag\nhas been set. Buffer Boundaries also allow you to match the start/end of a line *and* the start/end of \nthe input in a single RegExp using the `m` flag.\n\nWhile its possible to emulate `\\A` and `\\z` using existing patterns, the alternatives are harder to\nfar read, and require a more comprehensive working understanding of regular experssions to interpret.\n\nFor example, compare the following approaches:\n\n```js\n// emulate `m`-mode `^` outside of `m`-mode:\nconst a = /^foo|(?\u003c=^|[\\u000A\\u000D\\u2028\\u2029])bar/u;\n\n// emulate non-`m`-mode `^` inside of `m`-mode using modifiers (proposed):\nconst b = /(?-m:^)foo|^bar/mu;\n\n// using `\\A`:\nconst c = /\\Afoo|^bar/mu;\n```\n\nIn the example above, it is far less likely that a reader will readily understand the expression in\nexample (a). Not only is the content of the regular expression much harder to read, but understanding\nits purpose requires interpreting how **six** different features of regular expressions interact: \ngrouping, positive lookbehind, the `^` metacharacer, disjunctions, character classes, and unicode escapes.\n\nExample (b) is a an improvement, but still requires the reader to visually balance the parentheses as\nwell as to interpret how **four** different regular expression features interact: grouping, modifiers\n(proposed), the `m` flag, and the `^` metacharacter.\n\nIn comparison, example (c) is far easier to read. It consists of a terse escape sequence consisting\nof only two characters (`\\A`), which makes it far easier to distinguish between special pattern syntax\nand plain text segments like `foo` and `bar`. \n\nThe `\\A` and `\\z` escapes have broad support across multiple other languages and regular expression \nengines. As a result it has the benefit of extensive existing documentation online, including \n[Wikipedia](https://en.wikipedia.org/wiki/Regular_expression#Examples), numerous tutorial websites, as\nwell as the documentation from other languages. This significantly lessens the learning curve for `\\A`\nover its alternatives.\n\n\u003c!--#endregion:motivations--\u003e\n\n\u003c!--#region:prior-art--\u003e\n# Prior Art \n\n* [Perl](https://rbuckton.github.io/regexp-features/engines/perl.html#feature-buffer-boundaries)  \n* [PCRE](https://rbuckton.github.io/regexp-features/engines/pcre.html#feature-buffer-boundaries)  \n* [Boost.Regex](https://rbuckton.github.io/regexp-features/engines/boost.regex.html#feature-buffer-boundaries)  \n* [.NET](https://rbuckton.github.io/regexp-features/engines/dotnet.html#feature-buffer-boundaries)  \n* [Oniguruma](https://rbuckton.github.io/regexp-features/engines/oniguruma.html#feature-buffer-boundaries)  \n* [Hyperscan](https://rbuckton.github.io/regexp-features/engines/hyperscan.html#feature-buffer-boundaries)  \n* [ICU](https://rbuckton.github.io/regexp-features/engines/icu.html#feature-buffer-boundaries)  \n* [Glib/GRegex](https://rbuckton.github.io/regexp-features/engines/glib-gregex.html#feature-buffer-boundaries)  \n\nSee https://rbuckton.github.io/regexp-features/features/buffer-boundaries.html for additional information.\n\n\u003c!--#endregion:prior-art--\u003e\n\n\u003c!--#region:syntax--\u003e\n# Syntax\n\nBuffer boundaries are similar to the `^` and `$` anchors, except that they are not affected by the `m` (multiline) flag:\n\n- `\\A` \u0026mdash; Matches the start of the input.\n- `\\z` \u0026mdash; Matches the end of the input.\n- ~~`\\Z` \u0026mdash; A zero-width assertion consisting of an optional newline at the end of the buffer. Equivalent to `(?=\\R?\\z)`.~~\n\n\u003e NOTE: Requires the `u` or `v` flag, as `\\A`, `\\z`, and `\\Z` are currently just escapes for `A`, `z` and `Z` without the `u` or `v` flag. \n\n\u003e NOTE: Not supported inside of a character class.\n\n\u003e NOTE: The `\\Z` assertion is no longer being considered as part of this proposal as of December 15th, 2021, but has\n\u003e been reserved for possible future use.\n\nFor more information about the `v` flag, see https://github.com/tc39/proposal-regexp-set-notation.\n\n~~For more information about the `\\R` escape sequence, see https://github.com/tc39/proposal-regexp-r-escape.~~\n\n\u003c!--#endregion:syntax--\u003e\n\n\u003c!--#region:semantics--\u003e\n\u003c!-- # Semantics --\u003e\n\n\n\u003c!--#endregion:semantics--\u003e\n\n\u003c!--#region:examples--\u003e\n# Examples\n\n```js\n// without buffer boundaries\nconst pattern = String.raw`^foo$`;\nconst re1 = new RegExp(pattern, \"u\");\nre1.test(\"foo\"); // true\nre1.test(\"foo\\nbar\"); // false\n\nconst re2 = new RegExp(pattern, \"um\");\nre1.test(\"foo\"); // true\nre1.test(\"foo\\nbar\"); // true\n\n// with buffer boundaries\nconst pattern = String.raw`\\Afoo\\z`;\nconst re1 = new RegExp(pattern, \"u\");\nre1.test(\"foo\"); // true\nre1.test(\"foo\\nbar\"); // false\n\nconst re2 = new RegExp(pattern, \"um\");\nre1.test(\"foo\"); // true\nre1.test(\"foo\\nbar\"); // false\n\n// mixing buffer boundaries and anchors\nconst re = /\\Afoo|^bar$|baz\\z/um;\nre.test(\"foo\");         // true\nre.test(\"foo\\n\");       // true\nre.test(\"\\nfoo\");       // false\n\nre.test(\"bar\");         // true\nre.test(\"bar\\n\");       // true\nre.test(\"\\nbar\");       // true\n\nre.test(\"baz\");         // true\nre.test(\"baz\\n\");       // false\nre.test(\"\\nbaz\");       // true\n```\n\n\u003c!--#endregion:examples--\u003e\n\n\u003c!--#region:api--\u003e\n\u003c!-- # API --\u003e\n\n\u003c!--#endregion:api--\u003e\n\n\u003c!--#region:grammar--\u003e\n\u003c!-- # Grammar\n\n```grammarkdown\n``` --\u003e\n\u003c!--#endregion:grammar--\u003e\n\n\u003c!--#region:references--\u003e\n\u003c!-- # References\n\n\u003e TODO: Provide links to other specifications, etc.\n\n* [Title](url)   --\u003e\n\u003c!--#endregion:references--\u003e\n\n# History\n\n- October 28, 2021 \u0026mdash; Proposed for Stage 1 ([slides](https://1drv.ms/p/s!AjgWTO11Fk-TkfoSnHYFCoo4mYndTA?e=r0YIxu))\n  - Outcome: Advanced to Stage 1\n- December 15, 2021 \u0026mdash; Proposed for Stage 2 ([slides](https://1drv.ms/p/s!AjgWTO11Fk-Tkfs-sKyEtV6B_S-poQ?e=U7ToKV))\n  - Outcome: `\\A` and `\\z` advanced to Stage 2 (`\\Z` did not advance, but will be reserved)\n  - Stage 2 Reviewers: Richard Gibson, Waldemar Horwat\n\n\u003c!--#region:todo--\u003e\n# TODO\n\nThe following is a high-level list of tasks to progress through each stage of the [TC39 proposal process](https://tc39.github.io/process-document/):\n\n### Stage 1 Entrance Criteria\n\n* [x] Identified a \"[champion][Champion]\" who will advance the addition.  \n* [x] [Prose][Prose] outlining the problem or need and the general shape of a solution.  \n* [x] Illustrative [examples][Examples] of usage.  \n* [ ] ~~High-level [API][API].~~  \n\n### Stage 2 Entrance Criteria\n\n* [x] [Initial specification text][Specification].  \n* [ ] ~~[Transpiler support][Transpiler] (_Optional_).~~  \n\n### Stage 3 Entrance Criteria\n\n* [x] [Complete specification text][Specification].  \n* [ ] Designated reviewers have [signed off][Stage3ReviewerSignOff] on the current spec text.  \n* [ ] The ECMAScript editor has [signed off][Stage3EditorSignOff] on the current spec text.  \n\n### Stage 4 Entrance Criteria\n\n* [ ] [Test262](https://github.com/tc39/test262) acceptance tests have been written for mainline usage scenarios and [merged][Test262PullRequest].  \n* [ ] Two compatible implementations which pass the acceptance tests: [\\[1\\]][Implementation1], [\\[2\\]][Implementation2].  \n* [ ] A [pull request][Ecma262PullRequest] has been sent to tc39/ecma262 with the integrated spec text.  \n* [ ] The ECMAScript editor has signed off on the [pull request][Ecma262PullRequest].  \n\u003c!--#endregion:todo--\u003e\n\n\u003c!-- The following links are used throughout the README: --\u003e\n\n[Process]: https://tc39.es/process-document/\n[Proposals]: https://github.com/tc39/proposals/\n[Grammarkdown]: http://github.com/rbuckton/grammarkdown#readme\n[Champion]: #status\n[Prose]: #motivations\n[Examples]: #examples\n[API]: #api\n[Specification]: https://tc39.es/proposal-regexp-buffer-boundaries\n\n[Transpiler]: #todo\n[Stage3ReviewerSignOff]: #todo\n[Stage3EditorSignOff]: #todo\n[Test262PullRequest]: #todo\n[Implementation1]: #todo\n[Implementation2]: #todo\n[Ecma262PullRequest]: #todo\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-regexp-buffer-boundaries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftc39%2Fproposal-regexp-buffer-boundaries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-regexp-buffer-boundaries/lists"}