0

I am performing search on html document using javascript. For that I am using javascript's match function. Below line is to return all searchString matchings.

var searchResults = document.body.innerText.match(RegExp(searchString,'gi'));

The problem is, if the searchString contains special characters, i.e, (, &, <, etc, it's not working.

Example string "hello("

Please help me.

hwnd
  • 65,661
  • 4
  • 77
  • 114
Raj
  • 277
  • 2
  • 5
  • 12
  • Search for "javascript regular expression escape" to find lots of implementations of a function that will return the string with all regex chars escaped. – T.J. Crowder Sep 17 '13 at 21:01
  • This is my own implementation of escaping literal string for use in RegExp. http://stackoverflow.com/a/15004308/1400768 – nhahtdh Sep 17 '13 at 21:02
  • Thanks, that helped. :) – Raj Sep 18 '13 at 23:24

0 Answers0