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

The Archive Base Latest Questions

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

I am trying to create an html parser like BBCode. For example I want

  • 0

I am trying to create an html parser like BBCode.
For example I want to parse items from html text with the following format:
.....html..... [I]Item1[/I].....html....[I]Item2[/I]......
So I am using a regular expression to get the [I]XXXXX[/I] I also want the regex to return only the Item1 to avoid str_replace. At the moment I am using str_replace [I] with "" and [/I] with "" to get the Item1. The problem is that the regular expression is not always working.
I am using the code bellow:

$pattern="/\[I]([^\[].)+\[\/I]/m";
preg_match_all($pattern,$string,$out,PREG_SET_ORDER);
foreach($out as $i)
{
    $temp=$i[0];
    echo "Found!";
    $i[0]=str_replace("[I]","",$i[0]);
    $i[0]=str_replace("[/I]","",$i[0]);
    ......
}

My regular expression means: Starts with [I] continues with any character except [ (To avoid [I] [I] [/I] [/I]) and ends with [/I]. Some strings are failing such as aaaaa and others like aaa aa are found! Maybe there is a better way to create such an html parser?
Thank you!

Edit: Ok, I found the solution, but I can’t understand why this doesn’t work!
The solution was $pattern='#\[i\](.*?)\[/i\]#is' but whats the difference?

Edit 2: Raider was correct the main problem was in ([^\[.)+]. This will create the language [I](a)^2n[/I] so it will match [I]aa[/I], but not [I]aaaaa[/I]!

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

    I think your subpattern ([^\[].)+ is the problem. Try ([^\[]+)

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

Sidebar

Related Questions

I'm trying to create text in html, that once clicked, the the value of
I am trying to create some dynamic html out of some data from db.
I am trying to create a checkbox dynamically using following HTML/JavaScript. Any ideas why
I'm trying to create css buttons by using the following html markup: <a href=access.php
I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program.
I'm trying to create a generalized HTML parser that works well on Blog Posts.
I'm trying to create a small html fragment (a div element) consisted of three
I'm trying to create a custom HTML Helper to help simplify my masterpages menu,
I'm trying to create a horizontal 100% stacked bar graph using HTML and CSS.
I'm trying to create a self-contained version of pisa (html to pdf converter, latest

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.