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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:44:13+00:00 2026-05-30T04:44:13+00:00

I need to get the javascript replace() function to replace every instance of a

  • 0

I need to get the javascript replace() function to replace every instance of a [b] or [/b] with <b> or </b>. I tried this with the global tag but it doesn’t work and comes out oddly:

document.write(str.replace(/[b]/g,'<b>').replace(/[/b]/g,'</b>'));

results in the output being:

[<>]<>la<>la[<>][<>]<>la<>la[<>] 

I also tried changing the first part to:

  document.write(str.replace(/[[b]]/g,'<b>').replace(/[[/b]]/g,'</b>'));

which kind of works, but there’s odd ]s everywhere… like so:

[blabla[/[blabla[/

I know there’s probably something obvious I’m missing here… But I can’t find it… any help and I will love you forever XD

  • 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-30T04:44:14+00:00Added an answer on May 30, 2026 at 4:44 am

    [, ] and / are special RegExp characters.

    • [a] means: Match any a character. [abcd] means: Match one character, which is one of a, b, c, d. [a-z] means: Match any letter.
    • / is used to mark the beginning and end of a RegExp.

    To use the literal characters, they have to be escaped.

    str.replace(/\[b\]/g,'<b>').replace(/\[\/b\]/g,'</b>')
    

    Note that both Regular expressions can be merged, using a backreference:

    str.replace(/\[(\/?)b\]/g,'<$1b>')
    // Replaces [b] with <b>, [/b] with </b>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get a Javascript file to minity like this? eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return
I'm trying to replace the contents of a td tag in a javascript function
I need to get textbox that exits in Formview inserttemplate via javascript. Both return
i need to get number of order highlighted element (by javascript, jquery): <li>A</li> <li>B</li>
I'm working on some ECMAScript/JavaScript for an SVG file and need to get the
I have a <select>. Using JavaScript, I need to get a specific <option> from
I need to get the default printer name. I'll be using C# but I
I've been using John Resig's getStyle function from Pro JavaScript Techniques to get the
I'm defining a Javascript function in my KRL global block that I want to
I need a JavaScript function that goes through all of the elements of a

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.