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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:50:07+00:00 2026-05-18T11:50:07+00:00

I am boggled by regex I think I’m dyslexic when it comes to these

  • 0

I am boggled by regex I think I’m dyslexic when it comes to these horrible bits of code.. anyway, there must be an easier way to do this- (ie. list a set of replace instances in one line), anyone? Thanks in advance.

function clean(string) {
    string = string.replace(/\@~rb~@/g, '').replace(/}/g, '@~rb~@');
    string = string.replace(/\@~lb~@/g, '').replace(/{/g, '@~lb~@');
    string = string.replace(/\@~qu~@/g, '').replace(/\"/g, '@~qu~@');
    string = string.replace(/\@~cn~@/g, '').replace(/\:/g, '@~cn~@');
    string = string.replace(/\@-cm-@/g, '').replace(/\,/g, '@-cm-@');
    return string;
}
  • 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-18T11:50:08+00:00Added an answer on May 18, 2026 at 11:50 am

    You can define either a generic function, which would make sense if you can reuse it in more parts of your code, thus making it DRY. If you don’t have reason to define a generic one, I would compress only the part which cleans sequences and leave the other replaces as they are.

    function clean(string) {
        string = string.replace(/\@~rb~@|\@~lb~@|\@~qu~@|\@~cn~@|\@-cm-@/g, '')
          .replace(/}/g, '@~rb~@').replace(/{/g, '@~lb~@')
          .replace(/\"/g, '@~qu~@').replace(/\:/g, '@~cn~@')
          .replace(/\,/g, '@-cm-@');
        return string;
    }
    

    But be careful, the order of the replacements were changed it in this code.. although it seems they might not affect the result.

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

Sidebar

Related Questions

Recently, I was trying to debug some code and my mind was boggled as
I'm a bit boggled by something, I hope the CLR gearheads can help. Apparently
So my task may sound simple, but it has me boggled. I have looked
I am adding mobile layout and everything is set however there is a massive
The following problem boggled my mind, so I came here for some help. After
For reference, this question was boggled, so thanks to everyone who helped unboggle it.
I'm really curious right now. I'm a Python programmer, and this question just boggled
My mind is a bit boggled... in the following XML, I would expect my
I'm pretty new to Perl and trying to convert some PHP code to Perl.
I am trying to code a word descrambler like this one here and was

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.