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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:24:09+00:00 2026-06-14T04:24:09+00:00

I have a field of text where users can write specific command to get

  • 0

I have a field of text where users can write specific command to get some html.

For example:

Text Text Text Text

[*] first entry
[*] second entry
[*] 3rd...

Text Text

This text should be converted with regex to something like this:

text text

<ol>
 <li>FirstEntry</li>
 <li>Second</li>
 ..
</ol>

text text

Any suggestion?

The regex that matches the line with entry is something like this:

/\[\*\].+/i

The problem is how to insert correctly the <ol> and </ol>

My solution

I was thinking I could parse all line of text and when the parser encouter the first line that starts with [*] then put an <ol> Same thing for the </ol>

Until now I have made the script that converst single [*] ... to <li> ...

http://codepad.org/yzRVupON

preg_replace('/\[\*\](.+)/i','<li>$1</li>',$str);

I need the <ol> part

My implementation

http://codepad.org/NNgC6uko

  • 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-06-14T04:24:10+00:00Added an answer on June 14, 2026 at 4:24 am

    Doing this kind of parsing with regular expressions is probably not the way to go; it might be OK for very simple scenarios but the more features you try to put in the harder it will get — until the point where it becomes unmaintainable.

    I would suggest borrowing parsing techniques from e.g. various MarkDown parsers out there; see these questions for more information (there are others too).

    Back to the original question: if you are constrained to only using regular expressions you could try matching the whole “list block” first with something like

    /^(\s*\[\*\].*?$)+/m
    

    (the multiline mode modifier is essential)

    You can then produce the output by breaking the matched text down into individual list items with your current regex and then surrounding the result with <ol></ol>.

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

Sidebar

Related Questions

I have one text field where user can write short message (like status on
I would like to have a text field that a user can enter a
I have a form where users can add input fields with jQuery. <input type="text"
I have a field where the user can input text and I want them
I have a listbox that users can add/remove from. To add, there's a text
I'm making an app where users can write reviews on venues and currently have
I have an input field with some pre defined text explaining what it is
I was trying to write a script that checks the second text field if
I currently have 2 text fields where users enter full numbers, these are then
i have a text field in Contact screen and the user need to enter

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.