Adding DOTALL modifier to ECMAScript regex standards

# Jake Reynolds (8 years ago)

Hello,

I brought up the topic of adding the DOTALL modifier to the Chrome V8 Engine here groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/K9h0qB3Z3Gw

and was directed to es-discuss. I was curious about the practicality and the want for adding a DOTALL modifier to the ECMAScript standards in the future?

For those that don't know that DOTALL modifier is a regex modifier that allows the '.' symbol to match newlines as well.

Example regex: /he[.*]?llo/

Example search string 1: hello

Example search string 2: he

llo

The above regex will match the 1st search string but will not match the 2nd.

In ECMAScript the only current way to make a match like that work is to use [\d\D] which will match everything including newlines, given below.

Current workaround regex: /he[\d\D]?llo/

The s modifier is the standard in most major languages except Javascript and Ruby. This will allow newline matching for the . symbol. The proposed regex is below:

Proposed new regex: /he[.*]?llo/s

Example search string: he

llo

Let me know if there is any more information I can provide, or any questions you have.

Thanks much, Jake

# Andrea Giammarchi (8 years ago)

Just to double check, your /he[\d\D]?llo/ should be /he[\d\D]*?llo/, right? Otherwise it's not the same as /he[.*]?llo/

# Jake Reynolds (8 years ago)

Correct, sorry about that. I should have verified in a regexr before typing up the examples.

# Bob Myers (8 years ago)

If it's any consolation there is the more compact hack of [^], which I think is supposed to work everywhere.

# Mathias Bynens (8 years ago)

On Wed, Aug 10, 2016 at 4:40 PM, Bob Myers <rtm at gol.com> wrote:

If it's any consolation there is the more compact hack of [^], which I think is supposed to work everywhere.

That doesn’t work in IE < 9, but that shouldn’t matter in 2016.

# Jake Reynolds (8 years ago)

I agree, I doubt functionality in IE8- will matter, but I was thinking it would be nice to align the regex modifiers with other languages for the future.

Java: docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#DOTALL Python: docs.python.org/2/library/re.html#re.DOTALL C#: msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions(v=vs.110).aspx

There is a variety of namings for this across the languages (DOTALL/SINGELINE) but I believe the most often used modifier to be /.../s which would be a nice addition to have.

# Jake Reynolds (8 years ago)

My response bounced back to me, not sure if it went through.

I agree, I doubt functionality in IE8- will matter, but I was thinking it would be nice to align the regex modifiers with other languages for the future.

Java: docs.oracle.com/javase/7/docs/api/java/util regex/Pattern.html#DOTALL Python: docs.python.org/2/library/re.html#re.DOTALL C#: msdn.microsoft.com/en-us/library/system.text. regularexpressions.regexoptions(v=vs.110).aspx

There is a variety of namings for this across the languages (DOTALL/SINGELINE) but I believe the most often used modifier to be /.../s which would be a nice addition to have.

# Mathias Bynens (8 years ago)

On 10 Aug 2016, at 16:02, Jake Reynolds <jreynoldsdev at gmail.com> wrote:

I brought up the topic of adding the DOTALL modifier to the Chrome V8 Engine here and was directed to es-discuss. I was curious about the practicality and the want for adding a DOTALL modifier to the ECMAScript standards in the future?

For those that don't know that DOTALL modifier is a regex modifier that allows the '.' symbol to match newlines as well.

Example regex: /he[.*]?llo/ Example search string 1: hello Example search string 2: he llo

The above regex will match the 1st search string but will not match the 2nd.

In ECMAScript the only current way to make a match like that work is to use [\d\D] which will match everything including newlines, given below.

Current workaround regex: /he[\d\D]?llo/

The s modifier is the standard in most major languages except Javascript and Ruby. This will allow newline matching for the . symbol. The proposed regex is below:

Proposed new regex: /he[.*]?llo/s Example search string: he llo

Formal proposal (incl. proposed spec changes) for this feature: mathiasbynens/es

# Jake Reynolds (8 years ago)

Formal proposal (incl. proposed spec changes) for this feature:

mathiasbynens/es-regexp-singleline-flag

Very well written, thank you for writing that up. I've not been part of this process before so I'm not sure how it works, but if there is anything you need/want from me feel free to reach out.

Thanks, Jake