Reputation: 13
I am trying to get Ruby to search a text for certain characters, such as #
and $
. I then want to capture the character and the text beside it until there is white space, so if I would put this as text:
Hey, I am a #string and #what are you?
It would return the index at where the #string
and #what
are. This line only returns if the text has a special character:
<div class='tweet-text'>
<% if feed.text.match(/#\w+/) %>
Hi
<% end %>
</div>
The point here is I want to color the "#" word to a different color. The code is inside ejs. How would I do this?
Upvotes: 0
Views: 489
Reputation: 106792
When you want to highlight or mark one or more phrases in a text then you might want to have a look at the highlight
view helper:
For example
<%= highlight('Hey, I am a #string and #what are you?', /#\w+/) %>
will return
Hey, I am a <mark>#string</mark> and <mark>#what</mark> are you?
Upvotes: 4