0

I am trying to match a string exactly with special characters.

Example String

   Hard Drive (Red)

Since I have '(' and ')' in my string ,I am not able to match the string exactly.What i have tried,most of them works only for the string like

  /^ Hard Drive $/

This works only if there is no ( )

But,

  /^ Hard Drive(Red) $/

The above is incorrect regEx.What i am trying is to match a string exactly with special characters in it.

Sathya Narayanan GVK
  • 849
  • 2
  • 16
  • 32
  • `()` are special characters in regex you need to escape the `/^ Hard Drive\(Red\) $/` – Code Maniac Aug 08 '19 at 12:12
  • There are some [more special chars](https://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions) in a regex. Escape them with ``\``, or, to create a dynamic patter, [escape the literal part](https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript) when passing it to the `RegExp` constructor. – Wiktor Stribiżew Aug 08 '19 at 12:14

0 Answers0