「整数表現が 0 ~ 31 の範囲にある文字」に当てはまる正規表現を脳直で\u0000-\u0031
としてしまって、半角スペースも置き換えるようになってしまった。
javaユニコードエスケープは16進数表現であることに気づき修正。
import java.util.regex.Pattern
final val ForbiddenWindowsFilenameCharsRegexPattern = Pattern.compile("""[<>:"/|?*\\\u0000-\u001F]""")
def replaceForbiddenCharWithUnderscore(str: String): String =
ForbiddenWindowsFilenameCharsRegexPattern.matcher(str).replaceAll("_")