Use parameters in regexp

Hi, I was trying to use parameters in the regular expression like this:

regexp(Alias, /^$alias.*$/i)

But it seems returns nothing. However, if I just do a simple search like:

regexp(Alias, /$alias/i)

it works.

SO I’m wondering how should I inject the parameter in the first query.

Hi Freddie,

Why are you using the dollar sign in the beginning?

Test on any example and define the reasons for the expression. Explain what you want to do.

e.g (that you can use on play Dgraph):

  directors(func: regexp(name@en, /^steven.*$/i)) {

OneLine // treat ^ and $ as only matching at beginning and end of text
WasDollar // regexp OpEndText was $, not \z

Hi Michel,

Thanks for the reply.

Because $alias is the valuable that I pass into the query.

query test($dir: string = "steven"){
  directors(func: regexp(name@en, /^$dir.*$/i)) {

How can I get it working?


Like this:

query test($name: string = "/^Steven.*$/i") {
  directors(func: regexp(name@en, $name)) {

You can also run this query in as it is.

Oh, you’re right. I haven’t thought about it this way.

Thanks a lot.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.