faunadb

How can I match a full string in FaunaDB using ContainsStrRegex?


I'm trying to match a full string of digits using the following expression in Fauna Query Language:

q.ContainsStrRegex("123", "^\d*$")

This returns false. Just "\d*$" seems to work so I would imagine there's a different -1th match pattern. What do I need to do?


Solution

  • Your host language, which looks like JavaScript, is doing string parsing before the pattern makes it into the ContainsStrRegex function. "\d" means "make a string with this escaped 'd'", which is just "d".

    You need to escape the backslash to get it into the string, and subsequently into the function.

    q.ContainsStrRegex("123", "^\\d*$")