Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:18:38+00:00 2026-06-04T21:18:38+00:00

My goal is to find something like ‘b1234’ in a paragraph and replace it

  • 0

My goal is to find something like ‘b1234’ in a paragraph and replace it with:

<a href=http://bugtracker.com/bug/1234>b1234</a>

I made this using plain ruby:

"I fixed b1234 today".gsub(/(b([0-9]+))/i, '<a href=http://bugtracker.com/bug/\2>\1</a>')

It outputs:

=> "I fixed <a href=http://bugtracker.com/bug/1234>b1234</a> today" 

I have the following in my rails view:

<%= post.content %>

Note: I don’t store the HTML link code in my DB when posts are created.

If I do:

<%= post.content.gsub(...) %>

I get escaped html in the output file:

&lt;a href= ... instead of <a href= ...

…And I want that behavior, I don’t want users posting HTML (iframes would be scary!).

But, how I can I still get the find and replace functionality I want without sacrificing security? Maybe a Javascript approach?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:18:39+00:00Added an answer on June 4, 2026 at 9:18 pm

    Double up the equals signs. <%== post.content.gsub(...) %>. If users are also potentially writing HTML in this content, then you’ll need to Sanitize it, so that only specified HTML tags are permitted, for example.

    EDIT | Actually, provided the search string you are replacing does not contain HTML special characters, you can just escape the string, then do the gsub:

    <%== h(post.content).gsub(...) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal : How we can find the position of subView in a View. I
This is for the Apple platform. My end goal is to do a find
Goal I am building an Eclipse plugin targeting the 3.7 environment and would like
How would I design the tables for a matching system doing something like this:
I'm basically trying to get all touch event data from something like a system
I do not know whether it is possible but i want something like <f:view>
I'd like to add 2 methods to localStorage. My goal is to end up
I've got some inherited code that went something like this. (Please hold the laughter...
I have a project that I am working on it, need something like this:
I am trying to achieve something like this in a server control. <MyNewControl runat=server>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.