# Highlighting words in text

**URL:** <https://www.ruby-forum.com/t/highlighting-words-in-text/125114>\
**Category:** Rails\
**Created:** [January 5, 2008, 6:23pm UTC](https://www.ruby-forum.com/t/highlighting-words-in-text/125114 "2008-01-05T18:23:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 5, 2008, 6:23pm UTC](https://www.ruby-forum.com/t/highlighting-words-in-text/125114/1 "2008-01-05T18:23:05Z")

</div>

If I have a string: @tmp = “This is a test string 1 2 3 testing…”  
and I want to higlight a string “test” when I show it on a page, so how  
I can do it?

Result shold be like this: “This is a **test** string 1 2 3  
**test** ing”

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 5, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/highlighting-words-in-text/125114/2 "2008-01-05T18:33:19Z")

</div>

\<%= highlight “your text”, [“test”], “ **\1** ” %\>

See the ActionView::Helpers::TextHelper#highlight method. 🙂

–Jeremy

On Jan 5, 2008 12:23 PM, Gi Ga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> >

–  
[http://www.jeremymcanally.com/](http://www.jeremymcanally.com/)

My books:  
Ruby in Practice

> **[Ruby in Practice](https://www.manning.com/books/ruby-in-practice)**
>
> Like Ruby itself, Ruby in Practice will make you more productive. The book shows you practical techniques and strategies for small projects and large-scale environments. A cookbook-style reference, it gives you concrete examples of systems...

My free Ruby e-book

> **[Site not found · DreamHost](http://www.humblelittlerubybook.com/)**
>
> The owner of this domain has not yet uploaded their website.

My blogs:

> **[Site not found · DreamHost](http://www.mrneighborly.com/)**
>
> The owner of this domain has not yet uploaded their website.

[http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 5, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/highlighting-words-in-text/125114/3 "2008-01-05T20:02:46Z")

</div>

Jeremy McAnally wrote:

> See the ActionView::Helpers::TextHelper#highlight method. 🙂

Sorry 🙂 Thanks!
