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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:33:49+00:00 2026-06-07T00:33:49+00:00

So I am searching a string for {x} where x is some number between

  • 0

So I am searching a string for {x} where x is some number between 1-9 and my regexp finds the first occurrence and runs the callback function but this is only called on the first found instance. For example, {2}Some{3}String will return the replacement value x number of times depending on the integer between the brackets so the function is returning 		Some{3} when I would like it to return 		Some			String.

I don’t know very much regexp but is there something that I need to add in-order to have the callback function executed on all matched occurrences?

Here’s the code

var string = "{2}Some{3}String";

function replaceWithTabs(propertyName) {  
  var regExp = new RegExp('\{[1-9]\}');
  function addTabs(match) { 

    var string = '',
        i = 0,
        length = match.substring(1,2);

    for(i; i < length; i++) {
        string += "&#09;";
    }
    return string;  
}  return propertyName.replace(regExp, addTabs);  }
  • 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-07T00:33:51+00:00Added an answer on June 7, 2026 at 12:33 am

    Use this RegExp literal instead:

    var regExp = /{[1-9]}/g;
    

    { or } is not a special symbol in Regular Expression so you can avoid slashes. g flag of RegExp means global match,without that you will only replace first match,but not all matches. Using literal instead of RegExp contstructor is preferred, because it’s faster.Also if you use RegExp constructor, you additionally need to escape \ symbols,because slash is special symbol in string literal. Consider this:

    var regliteral = /\./;
    //Similar with constructor
    var regconstructor = new RegExp('\\.');  //slash is special symbol in string,so we add extra slash before it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to do some extensive searching and string comparisons and for this I
Have been searching how to convert a dictionary to a string. But the results
I did some searching and there where others asking this question and answers to
I tried searching for this, but couldn't find much. It seems like something that's
I'm studying string searching algorithms now and wondering what algorithm is used for .NET
For the two string searching algorithms: KMP and suffix tree, which is preferred in
I'm searching a string for a certain pattern. $string = Monday: 08.00-18.00; $pattern =
I need to create an array by searching a string for occurrences of '['
I am searching for a string in Perl and storing it in another scalar
I am searching for the string <!--m--><li class=g w0><h3 class=r><a href= within the HTML

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.