ID:2051517
 
BYOND Version:510.1331
Operating System:Windows 10 Pro 64-bit
Web Browser:Firefox 44.0
Applies to:Dream Daemon
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:
The \s character class is not matching newline \n characters.
Reference Doc
(Side note, \S does not match \n either, which is CORRECT behavior.)

Code Snippet (if applicable) to Reproduce Problem:
proc/TestRegex(string, regexp)
var/regex/r = regex(regexp, "g")
var/matches = 0
world << "Regex: \"[ShowWhitespace(regexp)]\""
world << "Test String: \"[ShowWhitespace(string)]\""
while(r.Find(string))
world << "- Match [++matches]: \"[ShowWhitespace(r.match)]\""
if(matches)
world << "After replacement: \"[ShowWhitespace(replacetext(string, r, ""))]\""
else
world << "No Matches"
world << ""

proc/ShowWhitespace(string)
. = replacetext(string, "\n", "\\n")
. = replacetext(., "\t", "\\t")
. = replacetext(., " ", "·")

client/verb/TestTrim()
TestRegex(" \n Hello \t ", "^\\s+|\\s+$")


Expected Results:
Regex: "^\s+|\s+$"
Test String: "··\n··Hello··\t··"
- Match 1: "··\n··"
- Match 2: "··\t··"
After replacement: "Hello"


Actual Results:
Regex: "^\s+|\s+$"
Test String: "··\n··Hello··\t··"
- Match 1: "··"
- Match 2: "··\t··"
After replacement: "\n··Hello"


Workarounds:
Use [\s\n] instead.
Should I report all non-standard things I come across, or are some intentional?

Other inconsistencies being the lack of a "singleline" ("s") flag, and the fact that [^...] should always match \n, (if not included in the set) whether or not the multiline flag is set.
\s not matching newlines is intentional.

The "s" flag is unnecessary because regexes use the JavaScript-friendly form of being single-line by default.

Inverse character classes [^...] should match newlines now as long as the multiline flag is set; that bug was fixed.
Actually, Javascript doesn't have single-line mode whatsoever. It's generally suggested to use [\s\S] in Javascript if you need to match any character, however that won't work here in BYOND since neither \s nor \S match newline.