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 254545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:51:20+00:00 2026-05-11T21:51:20+00:00

First off I don’t know much about regex and need to buy a book

  • 0

First off I don’t know much about regex and need to buy a book because it’s has proven to me to be difficult to pickup.

Ultimately I want to take a dom element, and replace text within straight brackets “[” and “]” and insert a link around the text, and there may be multiple bracket sets in the string.

function changeTip() {  
        var link = '<a href="' + $('#txtURL').attr('value') + '" target="_blank">';
        $('.tipoftheweektip').html($('#txtTip').attr("value").replace('[', link).replace(']', '</a>'));
    }

This works except:

  • doesnt work on the second set of brackets
  • if there isnt a closing straight bracket, it deletes all the text before the opening straight bracket

I’ve looked at examples and because straight brackets are used in the regex code, I cant figure out how to look for a bracket and replace it.

Anyone out there that has done something similar that they can share? Thanks in advance.

  • 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-05-11T21:51:20+00:00Added an answer on May 11, 2026 at 9:51 pm
    .replace(/\[([^\]]*)\]/g, link + "$1</a>")
    

    which means, find text between [ and ] and replace it with the value of link, the text itself and ”. This ensures matching square brackets. The ‘g’ means ‘do it multiple times (globally)’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first off I'm going to say I don't know a whole lot about theory
First off I want to start off saying that I don't know anything about
First off, don't link to the Don't parse HTML with Regex post :) I've
First off, I don't know if this is possible, but let me describe my
First off, I don't have any knowledge about java/jquery/ajax or such, but I think
(First off, thanks so much. Stackoverflow has been very helpful to me in the
First off, I know how to and has Integrated Windows Authentication in IIS7. This
First off, I don't know how to really show you guys what exactly I'm
First off, I'm embarassed that I don't know this. I know these things work,
First off, I know this may be a very stupid question, so don't shoot

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.