Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set word boundary using regex? #42

Open
aldrinrenzcruz opened this issue Jan 21, 2021 · 4 comments
Open

How to set word boundary using regex? #42

aldrinrenzcruz opened this issue Jan 21, 2021 · 4 comments

Comments

@aldrinrenzcruz
Copy link

aldrinrenzcruz commented Jan 21, 2021

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?

@code913
Copy link

code913 commented Feb 2, 2021

You could just put a \s around the word title

@aldrinrenzcruz
Copy link
Author

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

@code913
Copy link

code913 commented Feb 5, 2021

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

@aldrinrenzcruz
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants