highlight-within-textarea icon indicating copy to clipboard operation
highlight-within-textarea copied to clipboard

How to set word boundary using regex?

Open aldrinrenzcruz opened this issue 4 years ago • 4 comments

Please help.

In

highlight: 'title',
className: 'red'

I tried adding a /\btitle\b/g but it's not working and I'm not sure how to customize the library.

How can I add a word boundary for title so that it won't highlight "subtitle" or any other word with "title" in it?

aldrinrenzcruz avatar Jan 21 '21 12:01 aldrinrenzcruz

You could just put a \s around the word title

code913 avatar Feb 02 '21 07:02 code913

Please tell me how? I tried \stitle\s but it's not working?

aldrinrenzcruz avatar Feb 02 '21 08:02 aldrinrenzcruz

nvm that was wrong You could use lookaround: (?<=\b)title(?=\b)

code913 avatar Feb 05 '21 05:02 code913

Sorry this is still not working for me. Is this applicable to what I'm using which is inside quotation marks?

highlight: '(?<=\b)title(?=\b)',
className: 'red'

So something like that?

But thank you for trying to help me, really appreciate it!

aldrinrenzcruz avatar Feb 06 '21 07:02 aldrinrenzcruz