Thanks to @juancarlospaco, we now have Regular Expressions for the JavaScript target.
In jsre module above the runtime regex constructor is supported but the compile time constructor is not. Compile time constructor in javascript looks like this:
let re = /ab+c/;
My experiments:
jsrex1.nim
import jsre
func re*(pattern: cstring): RegExp {.importjs: "/#/".}
let re1 = re"abc" # in js: var re1 = /"abc"/
echo re1.test("abcde") # should be true but it is false
compiles, runs and gives wrong results since it builds the wrong regex (/"abc"/ instead of /abc/).
jsrex2.nim
import jsre
template re*(pattern: string) = {.emit: ["""/""", pattern, """/"""] .}
let re1: RegExp = re"abc" # Error: expression ' {.emit: ["""/""", r"abc", """/"""].}' has no type (or is ambiguous)
does not compile since emit section does not have a type.
jsrex3.nim
import jsre
func re*(pattern: cstring): RegExp {.importjs: "/$#/".}
let re1 = re"abc" # in js: var re1_623017 = "abc"./re/();
# it will give SyntaxError in Javascript
compiles but raises syntaxerror in JS. I did not expect this to work but I was a bit surprised by the results in JS code.
Is there a way to make this work?
Well, yes, you are right, I am blushing now. :)
Still, that expression literal is "compiled" when the script is loaded, or so I read. It also says that this could give a performance improvements, although thinking about it now, I guess it will not be much of an improvement (it just moves time of "compiling" the regex to load time instead of runtime).
So I guess there might not be much of an incentive to support this for JS (I could just use the regular construct in a func re). Still curious to see if it is possible to support this with Nim FFI, though.
But thats like an interpreter implementation detail almost an implementation bug, according to the official standard spec those should be basically the same, on other engines may or may not be the same, can even be the reverse.
But feel free to send Pull Request if you implement it.