{"id":13812658,"url":"https://github.com/tc39/proposal-regexp-dotall-flag","last_synced_at":"2025-05-14T22:30:56.407Z","repository":{"id":53015539,"uuid":"65715343","full_name":"tc39/proposal-regexp-dotall-flag","owner":"tc39","description":"Proposal to add the `s` (`dotAll`) flag to regular expressions in ECMAScript.","archived":true,"fork":false,"pushed_at":"2022-01-24T20:15:12.000Z","size":46,"stargazers_count":89,"open_issues_count":0,"forks_count":14,"subscribers_count":19,"default_branch":"main","last_synced_at":"2024-11-19T07:38:58.416Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tc39.github.io/proposal-regexp-dotall-flag/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"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":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-15T08:00:53.000Z","updated_at":"2024-04-03T22:10:38.000Z","dependencies_parsed_at":"2022-09-08T12:22:43.944Z","dependency_job_id":null,"html_url":"https://github.com/tc39/proposal-regexp-dotall-flag","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-dotall-flag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-regexp-dotall-flag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-regexp-dotall-flag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-regexp-dotall-flag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tc39","download_url":"https://codeload.github.com/tc39/proposal-regexp-dotall-flag/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254239456,"owners_count":22037713,"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:54.239Z","updated_at":"2025-05-14T22:30:51.377Z","avatar_url":"https://github.com/tc39.png","language":"HTML","funding_links":[],"categories":["JavaScript regex evolution"],"sub_categories":["Regex processors, utilities, and more"],"readme":"# ECMAScript proposal: `s` (`dotAll`) flag for regular expressions\n\n## Status\n\nThis proposal is at stage 4 of [the TC39 process](https://tc39.github.io/process-document/).\n\n## Motivation\n\nIn regular expression patterns, the dot `.` matches a single character, regardless of what character it is. In ECMAScript, there are two exceptions to this:\n\n* `.` doesn’t match astral characters. Setting the `u` (`unicode`) flag fixes that.\n* `.` doesn’t match [line terminator characters](https://tc39.github.io/ecma262/#prod-LineTerminator).\n\nECMAScript recognizes the following line terminator characters:\n\n* U+000A LINE FEED (LF) (`\\n`)\n* U+000D CARRIAGE RETURN (CR) (`\\r`)\n* U+2028 LINE SEPARATOR\n* U+2029 PARAGRAPH SEPARATOR\n\nHowever, there are more characters that, depending on the use case, [could be considered as newline characters](https://www.unicode.org/reports/tr14/):\n\n* U+000B VERTICAL TAB (`\\v`)\n* U+000C FORM FEED (`\\f`)\n* U+0085 NEXT LINE\n\nThis makes the current behavior of `.` problematic:\n\n* By design, it excludes _some_ newline characters, but not all of them, which often does not match the developer’s use case.\n* It’s commonly used to match _any_ character, which it doesn’t do.\n\nThe proposal you’re looking at right now addresses the latter issue.\n\nDevelopers wishing to truly match *any* character, including these line terminator characters, cannot use `.`:\n\n```js\n/foo.bar/.test('foo\\nbar');\n// → false\n```\n\nInstead, developers have to resort to cryptic workarounds like `[\\s\\S]` or `[^]`:\n\n```js\n/foo[^]bar/.test('foo\\nbar');\n// → true\n```\n\nSince the need to match any character is quite common, other regular expression engines support a mode in which `.` matches any character, including line terminators.\n\n* Engines that support constants to enable regular expression flags implement `DOTALL` or `SINGLELINE`/`s` modifiers.\n    * [Java](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#DOTALL) supports `Pattern.DOTALL`.\n    * [C# and VB](https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions.aspx) support `RegexOptions.Singleline`.\n    * Python supports both `re.DOTALL` and [`re.S`](https://docs.python.org/2/library/re.html#re.S).\n* Engines that support embedded flag expressions implement `(?s)`.\n    * [Java](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#DOTALL)\n    * [C# and VB](https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options)\n* Engines that support regular expression flags implement the flag `s`.\n    * [Perl](https://perldoc.perl.org/perlre.html#*s*)\n    * [PHP](https://secure.php.net/manual/en/reference.pcre.pattern.modifiers.php#s)\n\nNote the established tradition of naming these modifiers `s` (short for `singleline`) and `dotAll`.\n\nOne exception is Ruby, where [the `m` flag (`Regexp::MULTILINE`)](https://ruby-doc.org/core-2.3.3/Regexp.html#method-i-options) also enables `dotAll` mode. Unfortunately, we cannot do the same thing for the `m` flag in JavaScript without breaking backwards compatibility.\n\n## Proposed solution\n\nWe propose the addition of a new `s` flag for ECMAScript regular expressions that makes `.` match any character, including line terminators.\n\n```js\n/foo.bar/s.test('foo\\nbar');\n// → true\n```\n\n## High-level API\n\n```js\nconst re = /foo.bar/s; // Or, `const re = new RegExp('foo.bar', 's');`.\nre.test('foo\\nbar');\n// → true\nre.dotAll\n// → true\nre.flags\n// → 's'\n```\n\n### FAQ\n\n#### What about backwards compatibility?\n\nThe meaning of existing regular expression patterns isn’t affected by this proposal since the new `s` flag is required to opt-in to the new behavior.\n\n#### How does `dotAll` mode affect `multiline` mode?\n\nThis question might come up since the `s` flag stands for `singleline`, which seems to contradict `m` / `multiline` — except it doesn’t. This is a bit unfortunate, but we’re just following the established naming tradition in other regular expression engines. Picking any other flag name would only cause more confusion. The accessor name `dotAll` gives a much better description of the flag’s effect. For this reason, we recommend referring to this mode as _`dotAll` mode_ rather than _`singleline` mode_.\n\nBoth modes are independent and can be combined. `multiline` mode only affects anchors, and `dotAll` mode only affects `.`.\n\nWhen both the `s` (`dotAll`) and `m` (`multiline`) flags are set, `.` matches any character while still allowing `^` and `$` to match, respectively, just after and just before line terminators within the string.\n\n## Specification\n\n* [Ecmarkup source](https://github.com/tc39/proposal-regexp-dotall-flag/blob/master/spec.html)\n* [HTML version](https://tc39.github.io/proposal-regexp-dotall-flag/)\n\n## Implementations\n\n* [V8](https://bugs.chromium.org/p/v8/issues/detail?id=6172), shipping in Chrome 62\n* [JavaScriptCore](https://bugs.webkit.org/show_bug.cgi?id=172634), shipping in [Safari Technology Preview 39a](https://developer.apple.com/safari/technology-preview/release-notes/)\n* [XS](https://github.com/Moddable-OpenSource/moddable/blob/public/xs/sources/xsre.c), shipping in Moddable as of [the January 17, 2018 update](http://blog.moddable.tech/blog/january-17-2017-big-update-to-moddable-sdk/)\n* [regexpu (transpiler)](https://github.com/mathiasbynens/regexpu) with the `{ dotAllFlag: true }` option enabled\n    * [online demo](https://mothereff.in/regexpu#input=const+regex+%3D+/foo.bar/s%3B%0Aconsole.log%28%0A++regex.test%28%27foo%5Cnbar%27%29%0A%29%3B%0A//+%E2%86%92+true\u0026dotAllFlag=1)\n    * [Babel plugin](https://github.com/mathiasbynens/babel-plugin-transform-dotall-regex)\n* [Compat-transpiler of RegExp Tree](https://github.com/dmitrysoshnikov/regexp-tree#using-compat-transpiler-api)\n    * [Babel plugin](https://github.com/dmitrysoshnikov/babel-plugin-transform-modern-regexp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-regexp-dotall-flag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftc39%2Fproposal-regexp-dotall-flag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-regexp-dotall-flag/lists"}