bvaughn / react-highlight-words

React component to highlight words within a larger body of text
https://bvaughn.github.io/react-highlight-words/
MIT License
2.16k stars 170 forks source link

when trying to highlight a word starts with "(" - there's an error #52

Closed AsafShochet closed 6 years ago

AsafShochet commented 6 years ago

hi. thank for this lib :)

when using it, we encountered a situation where the word to be highlighted is: "(1 ".

<Highlighter searchWords={['(1 ']} textToHighlight={'hello'} />

and we got this error in console: Uncaught SyntaxError: Invalid regular expression: /(1 /: Unterminated group at new RegExp () at index.js:180 at Array.reduce () at defaultFindChunks (index.js:173) at findAll (index.js:112) at Highlighter (Highlighter.js:48) at mountIndeterminateComponent (react-dom.development.js:8574) at beginWork (react-dom.development.js:8978) at performUnitOfWork (react-dom.development.js:11814) at workLoop (react-dom.development.js:11843)

bvaughn commented 6 years ago

Hi. Check out the docs.

You can use the autoEscape prop, or you can escape the string yourself ("\(1").

Cheers! 😄

AsafShochet commented 6 years ago

thanks! I already escaped myself.