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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:23:52+00:00 2026-05-25T02:23:52+00:00

Good day, I would like to know if that’s possible using RegExp and if

  • 0

Good day,

I would like to know if that’s possible using RegExp and if so, how.

Here is the problem:

In a string, I have multiple pattern that correspond to colors:

{r for dark red
{R for bright red
{G for bright green
{W for white
{* for black
... and so on...

Sometimes the data I’m parsing contains lot of useless color changes
Example:

{r{Gthis text is finally green

The {r is totally useless there. It wouldn’t if the string was {rSomething {Gthis text is finally green

I would like a way to match every {<color references> that is right before any other {<color references> and leaves the last one in place.

{r{Gthis text is green -> {Gthis text is green
That text is {R{rdark red -> That text is {rdark red

Is that an easy way to do that?

I am aware that this problem is really particular and will probably never help anyone else.

But help would be really appreciate.

Thank you!

PS: The codes is used in Javascript so if possible, I would like a solution working in Javascript.

Edit:

I must be able to do {Y{r{Gthis te{*xt {Y{yis green and get {Gthis te{*xt {yis green

  • 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-25T02:23:52+00:00Added an answer on May 25, 2026 at 2:23 am

    Here’s a method that works. It works like this:

    1. Search for one or more color codes follow by another color code.
    2. A color code is considered a { followed by any other single character except a {. If there are only a specified set of color codes that you want to allow or there are more characters that are not allowable color codes, then those could also be added to the regex, but you didn’t specify that additional info.
    3. The regex for a single color code is this: \{[^\{]. This is a { followed by any single character that is not a {. If you want it to only be alpha characters, it could be changed to this: \{[a-zA-Z].
    4. Replace the multiple consecutive color codes with the last color code using the sub-matches from the match.
    5. This technique will remove all but the last color code even when there are more than two color codes in a row.
    6. This technique will not remove things that don’t look like valid color codes like {{.

    This works for any character in the color code since you looked like you had a long list of valid single character codes. But, it protects against {{ which it will not treat as a color code.

    var str = "{r{G{ythis text is finally green";
    var result = str.replace(/(\{[^\{])+(\{[^\{])/g, "$2");
    

    or to allow just alpha characters to be a color code character, it would be this:

    var result = str.replace(/(\{[a-zA-Z])+(\{[a-zA-Z])/g, "$2");
    

    You can see a test fiddle here: http://jsfiddle.net/jfriend00/jNXUz/

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

Sidebar

Related Questions

Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good morgning, I would like to be able to analyze text where I am
Good day, We just converted our web application .NET 1.1 to .NET 2.0. We
Good day, In visual studio 2005, when I drop a webcontrol in the designer,
I've spent a good part of the day searching, writing and finally scrapping a
Good morning. I have an XML file which contains lists of warning and errors
Good evening I've got a little problem with my DataGridView in a .NET Windows
Good morning, I am the developer of a medium sized PDA application that will
Good morning, I am about to start writing an Excel add-in for Excel 2002.
Good afternoon, This should be an easy one. I've done the cookie-cutter default ASP.NET

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.