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

Match accuracy settings are missing #40

Closed dkocich closed 6 years ago

dkocich commented 6 years ago

Hello, thanks for the library. In https://markjs.io/#mark there are few options how highlight should mark words - react-highlight-words works now in accuracy: "partially" mode only. Are there any plans to extend the settings in the near future? I am currently looking for the solution how to mark only exact match of words.

bvaughn commented 6 years ago

I'm not familiar with markjs.

react-highlight-words supports regular expression syntax by default, so you can turn on "exact" matching mode using the word boundary character \b. For example, searching "\bthe\b" will find exact matches for the word "the" while ignoring words like "other". 😄

I have no plans at this time to change the API.

dkocich commented 6 years ago

Good, thanks - that is useful to know however I am not sure if it really works how it should with different RegExp's. I do not see any tests for this case (using of boundary character - "\b") in https://github.com/bvaughn/react-highlight-words/blob/master/src/Highlighter.test.js . I managed to get this kind of search work with a double slash (\\bthe\\b) and autoEscape set to false.

bvaughn commented 6 years ago

I don't see great value in writing tests to verify regular expression behavior. My tests verify that the component accepts a regex. Beyond that I trust the browser to work.