Use GraphQL Vars In regex

I Want to Do

Use GQL variables in DQL query inside a regex filter

What I Did

query find_user($term: string){
  find_user(func: type(User)) @filter(regexp(User.username, /$term/i) or regexp(User.email, /^$term/i)){
    uid
    usern_name: User.username
    User.email
    User.full_name
  }
}

Problem

$ is a special character in regex

1 Like

You should try something like this

query q( $name: string = "/^Steven Sp.*$/", $name_ryan: string = "/ryan/i")  {
  directors(func: regexp(name@en, $name )) {
    name@en
    director.film @filter(regexp(name@en, $name_ryan)) {
      name@en
    }
  }
}