I have this regex of mine that will check the string if it contains link or url (i.e. https://eslint.org/docs/rules/no-useless-escape)
. Using this regex /(\\b
It's the \/
in [-A-Z0-9+&@#\/%?=~_|!:,.;]
and [-A-Z0-9+&@#\/%=~_|]
(NOT the ones in :\/\/
). Most characters do not have to be escaped within a character class (square brackets). This should be equivalent: /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig
So
See https://www.regular-expressions.info/charclass.html for more info, but the relevant part:
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.