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

  • Home
  • SEARCH
  • 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 6991753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:32:41+00:00 2026-05-27T19:32:41+00:00

var str=itss[BACK][BACK][BACK][BACK][BACK][BACK] it’s a test stringgg[BACK][BACK]; var word = ‘[BACK]’; var substrings = str.split(word);

  • 0
var str="itss[BACK][BACK][BACK][BACK][BACK][BACK] it's a test stringgg[BACK][BACK]";
var word = '[BACK]';
var substrings = str.split(word);
var cnt= substrings.length - 1;
for(var i = 0;i<cnt;i++){
  str = str.replace(/.{1}\[BACK\]{1}/i,""); //remove backspace and one character before it.
}

The above script returns something like “[BACK it’s a test string” I need to get this result as “it’s a test string” please help me….

  • 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-27T19:32:42+00:00Added an answer on May 27, 2026 at 7:32 pm

    It’s easier to do this without a regex actually.

    String.prototype.replaceFromIndex=function(index, length, replace) {
        return this.substr(0, index) + replace + this.substr(index+length);
    }
    
    var search = '[BACK]';
    var str="itss[BACK][BACK][BACK][BACK][BACK][BACK] it's a test stringgg[BACK][BACK]";
    
    while((index = str.indexOf(search)) >= 0){
        str = str.replaceFromIndex(index-1, search.length+1, '');    
    }
    
    alert(str);
    

    Check http://jsfiddle.net/fRThH/2/ for a working example.
    Wrap it in a function and you are ready to go!

    Courtesy to Cem Kalyoncu ( https://stackoverflow.com/a/1431113/187018 ) for a slightly modified version of String.prototype.replaceAt

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

Sidebar

Related Questions

var str = test's t\r and t\n; str = str.replace(/'/g, \'); str = str.replace(/\r/g,
If I have the following string: var str = Test.aspx?ID=11&clicked=false+5+3; str = str.replace(????????, 'true');
You can backreference like this in JavaScript: var str = 123 $test 123; str
var str = 'single words fixed string of words'; var astr = str.split( );
Given the following string: var str = one,two,three; If I split the string on
I have this code: var str = $(#datepicker).datepicker(getDate); var datestr = str.toString().split( ); switch(datestr[1])
var str = $('.rating').html(); $.trim(str); $('.rating').prepend.attr('class', 'rating-' + str.replace(/\s/g, )); <div class=rating>1</div> <div class=rating>2</div>
Alright, here's my current test function: function make_void( str ) { var str_arr =
var str = This is a string; var thing = str.replace(string,thing); console.log( str )
I have this code: var str = ' abc'; str.replace( ,); but it is

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.