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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:10:26+00:00 2026-05-15T22:10:26+00:00

Ok, so I have this: $fromArray = array( /(\[color=)(.+)(\])/, (\[\/color\])); $toArray = array( <span

  • 0

Ok, so I have this:

$fromArray = array(
"/(\[color=)(.+)(\])/",
"(\[\/color\])");

$toArray = array(
"<span style=\"color:\\2\">",
"</span>");

What that’s supposed to do it match all [color= to .

I’m running that, but this is what the source outputs:

<span style="color:red]RED<b>BOLD</b>RED[/color">

When I try to run

[color=red]RED[b]BOLD[/b]RED[/color]

through it.

What’s going on? I don’t know Regex very well, this is my first Regex. But I just can’t figure out why it’s creating that ugly source code that doesn’t work 🙁

Does anybody know?

Thank you 🙂

**In case somebody has NO IDEA what I want to do with that (it’s pretty unclear :), here’s it:

Translate [color=red] to<span style="color:red;">
Translate [/color] to </span>.

Now I need to do these separately, if I do them as one regex pattern it’ll mess up with another issue that would take days to explain :\

  • 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-15T22:10:26+00:00Added an answer on May 15, 2026 at 10:10 pm

    Use the non-greedy quantifier:

    $fromArray = array(
    "/(\[color=)(.+?)(\])/",
    "(\[\/color\])");
    

    What’s happening is that your regex for the start tag was actually gobbling up the start tag, the stuff in the middle, and the end tag, because .+ is greedy and matches as much as it can, so the \] was actually matching the bracket at the end of the close tag.

    The non-greedy version, .+?, matches as little as possible while still allowing the regex to match, and thus will make sure to only match the open tag.

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

Sidebar

Related Questions

I have an array that looks like this: var y = [1, 2, 3];
how i can duplicate one element from array: for example, i have this array:
This has bothered me for quite a while, but now it is necessity that
i have this json structure and I made it into an array. I was
This question was asked at interview.I need to have running total ( only using
I have the following query: $select = $this->getDao()->select() ->from( array(new Zend_Db_Expr('FROM_UNIXTIME(expiration)')) ); The getDao
I have to list several elements that are coming from a database source A
I have this array lets call it array 1 Array ( [0] => Array
i have this query that works fine SELECT t.username FROM users t LEFT JOIN
i have a javascript array like this: array = [ {Command: SetDuration,QuestionId: 2,NewDuration: 1},

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.