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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:07:20+00:00 2026-06-01T07:07:20+00:00

I wish to do a search and replace in a string. It searches for

  • 0

I wish to do a search and replace in a string. It searches for any word that begins with “$” and replaces it with a value from an array. For example if the string is:

[div class='news'][h4]$title[/h4][p]$desc[/p][/div]

It replaces [] to <> (already done). But then i want it to replace $title with data from an array. So data[“title”] and then $desc would be replaced with data[“desc”].
The code i have so far is

var obj = $('#'+id);
var url = $(obj).attr('loadJSON');
var format = $(obj).attr('responseFormat');
$.getJSON(url, function(data) {
    var html = "";
    for(var i=0;i<data.length;i++) {
        var tmp = format;
        tmp = tmp.replace(/\[+(.*?)\]+/g,"<$1>");
        tmp = tmp.replace();
    }
});

The format is the string which it will replace in, and data (from the JSON response) is the array which i want the variables to change to.

Could someone please help me with this? 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-06-01T07:07:21+00:00Added an answer on June 1, 2026 at 7:07 am

    then add as last replacement

    tmp = tmp.replace(/\$([a-z]+)/gi, function(match, v) {
       return data[v] || v;
    })
    

    note that in case of data[v] is undefined you could return something else like data[v] || ["not found", v].join(' ') just to track what variable is missing

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

Sidebar

Related Questions

I often wish to search for variables that are simply called 'c' or 'count'.
I have a massive amount of repeating code that I wish to replace in
We wish to make a desktop application that searches a locally packaged text database
I wish to search a database table on a nullable column. Sometimes the value
I have a search method that takes a list of ID's and I wish
I have a directory of ~100 plaintext files that I wish to search for
I wish I could throw a ! on a Google search, and turn up
Thought my range of search options would easily find this. I wish to combine
I wish to send an email from my localhost machine (using PHPs mail function)
I wish to be able to generate URL variables like this: http://example.com/195yq http://example.com/195yp http://example.com/195yg

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.