1

I have a url that contains two values, a keyword and a location name. The keyword comes after the '/r/' and the location after the '/l/'.
E.g: localhost:3000/search/r/keyword/l/location

To get only the value after the '/r/' (keyword) and the value after the '/l/' (location); I'm doing the following Regexr:

var cutResult = window.location.href.match(/\br\/\b(\b[^\/]+\b)/gi);
var cutLocation = window.location.href.match(/\b\/l\/\b(\b[^\/]+\b)/gi);

This does the trick, however, React returns following message:

Unnecessary escape character: / no-useless-escape

What causes the error?

jmargolisvt
  • 5,722
  • 4
  • 29
  • 46
Cédric Bloem
  • 1,447
  • 3
  • 16
  • 34

1 Answers1

3

You do not need to escape most of the characters inside a character class (inside [...]) only a few:

In most regex flavors, the only special characters or metacharacters inside a character class are the closing bracket ], the backslash \, the caret ^, and the hyphen -. The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash. To search for a star or plus, use [+*]. Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.

Carlos Ruana
  • 2,138
  • 1
  • 15
  • 14