Actions
Bug #19639
closedEscaped newline literals in Regexp are ignored in extended / free-spacing mode
Status:
Feedback
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21]
Description
When we want to match whitespace with a Regexp that uses the x-flag, we can do that with escaped literal whitespace:
' '[/\ /x] # => " "
This works for all whitespace - except newlines:
"\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 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.)
?
Updated by nobu (Nobuyoshi Nakada) 12 months ago
- 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.
Actions
Like0
Like0