Ire Aderinokun 12/18/2018

A one-line solution to highlighting search matches

Read Original

The article details a developer's journey to implement search term highlighting on a blog. After exploring complex solutions, they discovered a concise one-line method using JavaScript's String.replace() with a regex and a function to wrap matches in <mark> HTML tags. It explains the replace() method's capabilities and notes a key limitation: the solution only works with plain text, not pre-existing HTML.

A one-line solution to highlighting search matches

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

1
The Beautiful Web
Jens Oliver Meiert 2 votes
3
LLM Use in the Python Source Code
Miguel Grinberg 1 votes
4
Wagon’s algorithm in Python
John D. Cook 1 votes