1

I'm building an Angular webpage with top menu with a search input giving me some issues... I'm using RESTHeart API in order to build the query for it. In the query sent to the API I'm sending the following:

[a-zA-Z0-9.@-]{4,99}

This pattern should make sure the search input is case insensitive and this was not working well, so I looked at the documentation here https://restheart.org/learn/query-documents/ and the regex should include (?i) in order to be interpreted as "case insensitive". So I did - this is the pattern being sent:

(?i)[a-zA-Z0-9.@-]{4,99}

Now I get an error on the menu loading:

ERROR SyntaxError: Invalid regular expression: /^(?i)[a-zA-Z0-9.@-]{4,99}$/: Invalid group

I also tried hardcoding the (?i) part since it seems that the problem is in that particular part...

Anyone has any idea why this could be happening? I tried https://regex101.com/r/o684Hu/2/ and it works there...

Thank you for your time,

Eunito.

Eunito
  • 416
  • 5
  • 22
  • 2
    Your regular expression is already case-insensitive. Just remove inline modifier. The reason of that error is JS doesn't support inline modifiers. – revo Sep 21 '18 at 16:34
  • 1
    `(?i)` is a PCRE extnsion which is not supported by JavaScript. These online regex testers really should be much more explicit about which regex dialects they support and what will happen if you don't understand the differences. – tripleee Sep 21 '18 at 16:37

1 Answers1

1

In mongodb the $regex query operator allows options

With RESTHeart the query filter should be as follows for case insensitive regex query

GET /db/coll?filter={"field":{"$regex": "[a-zA-Z0-9.@-]{4,99}", "$options": "i"}}

for more info, check the options available for use with regular expression in mongodb documentation.

Andrea Di Cesare
  • 1,125
  • 6
  • 11