question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v5.1.0 - Op.regexp add unwanted backslahes & double quotes that breaks regex.

See original GitHub issue

What are you doing?

I try to use a regex to match one or many terms in the column.


let services = ['First'];

Model.findAll({
  where: {
    column: {
      [Op.regexp]: services[0]
    }
  }
});

What do you expect to happen?

I want that the mysql request look like that :

 `Model`.`column` REGEXP 'First'

What is actually happening?

Backslahes and doubles quotes are added in the generated request.

`Model`.`column` REGEXP  '\"First\"'

Dialect: mysql Dialect version: NA Database version: 5.7.25-0ubuntu0.18.04.2 Sequelize version: 5.1.0 Tested with latest release: Yes (5.1.0)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
Sorok-Dvacommented, Mar 24, 2019

Thanks for you quick answer and your temp fix.

So now I use

return Models.Wish.findAll({
    where: {
      services: {
        [Op.regexp]: Sequelize.literal(`'(${filterQuery.services[0]})'`)
      }
    }
  });

that works like a charm !

1reaction
SimonSchickcommented, Mar 24, 2019

For now try using literal(YOUR_VALUE) while I look into a bug fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the regex to match anything except a double quote not ...
So: match quotes, and inside them: every character except a quote ... That is, a double-quote preceded by two backslashes, where in most ......
Read more >
RegexBuddy PDF
enter with a backslash. Metacharacters are characters that have a special meaning in regular expressions. Non-Printable Character.
Read more >
RegexMagic Manual
Start with adding samples of the text that your regular expression should ... The source code snippet automatically sets the “dot matches line...
Read more >
Regex for Quoted String with escapable quotes - Metal Toad
The next important thing to realize is that the last character before the ending quote will not get matched. That's why we add...
Read more >
Regular Expressions :: Eloquent JavaScript
First, since a forward slash ends the pattern, we need to put a backslash before any forward slash that we want to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found