Variables in regexp with JavaScript client

The regexp is wrong. You’re using Javascript flavoured regular expressions. Dgraph supports proper regular expressions.

There shouldn’t be / in the regex. When you are using Ratel, / serves as a delimiter for the regular expression, much like " serves as a delimiter for strings. You’re passing in the regular expression as a string when calling via JS, not as a regular expression (object).

To construct your regex string, the following JS would work:

`.*${name}.*`

p/s: Don’t write .*. It’s a bad habit. Don’t write .+ either. Also a bad habit.
pp/s: proper regular expression doesn’t have name interpolation/variable or named capture. Those are called PCRE (Perl Compatible Regular Expressions), which are NOT Regular Expressions. I don’t think they’re even regular. Go only supports regular expressions.
ppp/s: yes, I am a stickler for formal language hierarchies.