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.
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.