[ruby-core:113477] [Ruby master Bug#19639] Escaped newline literals in Regexp are ignored in extended / free-spacing mode

Issue #19639 has been reported by janosch-x (Janosch Müller). ---------------------------------------- Bug #19639: Escaped newline literals in Regexp are ignored in extended / free-spacing mode https://bugs.ruby-lang.org/issues/19639 * Author: janosch-x (Janosch Müller) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- When we want to match whitespace with a Regexp that uses the x-flag, we can do that with escaped literal whitespace: ```ruby ' '[/\ /x] # => " " ``` This works for all whitespace - except newlines: ```ruby "\n"[/\ /x] # => "" /\ /x.source # => "" ``` I guess another parsing step eliminates such escaped newlines before the regexp parsing happens? It is probably a rare issue because most people prefer "\n" in Regexps over literal newlines, but at least the relevant statement in the [documentation](https://docs.ruby-lang.org/en/master/regexp_rdoc.html#label-Free-Spacing+Mod...) is a bit too broad as it is:
Use escaped whitespace such as \ , i.e. a space preceded by a backslash.
Maybe we want to add a caveat like `(Does not work for newlines.)`? -- https://bugs.ruby-lang.org/

Issue #19639 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Feedback I don’t think it is a bug, because a backslash at the end of line is line concatenation and those two chars are dropped, in general. ---------------------------------------- Bug #19639: Escaped newline literals in Regexp are ignored in extended / free-spacing mode https://bugs.ruby-lang.org/issues/19639#change-103062 * Author: janosch-x (Janosch Müller) * Status: Feedback * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- When we want to match whitespace with a Regexp that uses the x-flag, we can do that with escaped literal whitespace: ```ruby ' '[/\ /x] # => " " ``` This works for all whitespace - except newlines: ```ruby "\n"[/\ /x] # => "" /\ /x.source # => "" ``` I guess another parsing step eliminates such escaped newlines before the regexp parsing happens? It is probably a rare issue because most people prefer "\n" in Regexps over literal newlines, but at least the relevant statement in the [documentation](https://docs.ruby-lang.org/en/master/regexp_rdoc.html#label-Free-Spacing+Mod...) is a bit too broad as it is:
Use escaped whitespace such as \ , i.e. a space preceded by a backslash.
Maybe we want to add a caveat like `(Does not work for newlines.)`? -- https://bugs.ruby-lang.org/
participants (2)
-
janosch-x
-
nobu (Nobuyoshi Nakada)