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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:59:33+00:00 2026-05-28T13:59:33+00:00

I am very new to using preg_replace and such so please bear with me.

  • 0

I am very new to using preg_replace and such so please bear with me.

I have few hundreds line that contains this line

<strong>[*<a title="*" name="*"></a>]</strong><br /> Lorem ipsum

* on above code denotes that number such as 1,2,3

What i want to achieve is that

*. Lorem Ipsum

Example, 1. Lorem ipsum, 2. Lorem ipsum

What would be the best way to achieve it? Thanks.

sample text

<strong>[1<a title="1" name="1"></a>]</strong><br /> Lorem ipsum 12345<br /> <strong>[2<a title="2" name="2"></a>]</strong><br /> lorem ipsum asdasd<br /> <strong>[3<a title="3" name="3"></a>]</strong><br /> lorem ipsum asdsadasdasdasd<br />

it goes way up to hundreds

  • 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-28T13:59:33+00:00Added an answer on May 28, 2026 at 1:59 pm

    How about:

    $output = preg_replace('~^<strong>\[(\d+)<.*?<br\s*/>~', '$1. ', $input);
    

    explanation:

    ~             : regex delimiter
      ^           : start of line
      <strong>    : <strong> as is
      \[          : an open square bracket
      (\d+)       : capture one or more digits
      <.*?        : > followed by any number of any char
      <br\s*/>    : <br/> or <br />
    ~
    

    And replace all that match by the first captured group (ie. the digits) followed by a dot and a space.

    Edit according to comments:

    $input = '<strong>[1<a title="1" name="1"></a>]</strong><br /> Lorem ipsum 12345<br /> <strong>[2<a title="2" name="2"></a>]</strong><br /> lorem ipsum asdasd<br /> <strong>[3<a title="3" name="3"></a>]</strong><br /> lorem ipsum asdsadasdasdasd<br />';
    $output = preg_replace('~\s*<strong>\[(\d+)<.*?<br\s*/>(.*?)(?:<br />|$)~', "$1. $2\n", $input);
    echo $output,"\n";
    

    output:

    1.  Lorem ipsum 12345
    2.  lorem ipsum asdasd
    3.  lorem ipsum asdsadasdasdasd
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to using Glassfish or JSP. I have this working in NetBeans
I am very new to C++ and using Unix. I have a doubt that
So I am very new to using jQuery and I have a script that
I'm very new to using Linq-to-SQL, that's why I'm asking this question. I've searched
I still very new using Subversion. Is it possible to have a working copy
Guys i am very new to jQuery. I have started using the auto complete
I have built a very simple blog application using Ruby on Rails. New to
I have a problem using preg_match. (I'm very new to regular expressions) if(preg_match('^/http:\/\/myWebsite\.com\/', $_SERVER['HTTP_REFERER']))
Sorry if this is wrong or confusing I am very new to using classes
I am very new to C# and i have written the following class: using

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.