This code would produce different results.
I guess it's related to how string is escaped, it's confusing.
import re
echo "a b".split(re("\\s"))
echo "a b".split(re"\\s")
Result
@["a", "b"]
@["a b"]
In the first form the re is applied after the string literal is already parsed as a "normal" (non-raw) string \s. In the second form the string literal is parsed as a raw string \\s (see @Hlaaftana 's link).
For what it's worth, I was wondering if there's a way to query the regex object for the string it was created from, but I didn't find anything in the re documentation. Trying to echo the regex gives a type error and printing the repr isn't helpful (for me at least ;-) ).
I was wondering if there's a way to query the regex object for the string it was created from, but I didn't find anything in the re documentation.
I do not think it is possible to recover original pattern in re, since Regex object only contains pointer to pcre objects: https://github.com/nim-lang/Nim/blob/version-1-2/lib/impure/re.nim#L46
You can access directly the pattern if you use nre instead: https://nim-lang.org/docs/nre.html#Regex