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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:12:47+00:00 2026-06-13T20:12:47+00:00

Using PHP, I am looking to extract an array from a string that contains

  • 0

Using PHP, I am looking to extract an array from a string that contains a numbered list.

Example string:

The main points are: 1. This is point one. 2. This is point two. 3. This is point three.

would result in the following array:

[0] => 1. This is point one.
[1] => 2. This is point two.
[2] => 3. This is point three.

The format of the string can vary – e.g.:

1. This is point one, 2. This is point two, 3. This is point three.
1) This is point one  2) This is point two 3) This is point three
1 This is point one. 2 This is point two. 3 This is point three.

I have started using preg_match_all with the following pattern:

!((\d+)(\s+)?(\.?)(\)?)(-?)(\s+?)(\w+))!

but I am unsure as how to match rest of string/up to the next match.

Example available at RegExr

  • 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-13T20:12:48+00:00Added an answer on June 13, 2026 at 8:12 pm

    If your input follows your example input, as in each “point” doesn’t contain a number itself, you could use the following regex:

    \d+[^\d]*
    

    In PHP, you could use preg_match_all() to capture everything:

    $text = 'The main points are: 1. This is point one. 2. This is point two. 3. This is point three.';
    
    $matches = array();
    preg_match_all('/(\d+[^\d]*)/', $text, $matches);
    
    print_r($matches[1]);
    

    This will result in:

    Array
    (
        [0] => 1. This is point one.
        [1] => 2. This is point two.
        [2] => 3. This is point three.
    )
    

    Again though, if there are any numbers/digits in the actual points themselves – this won’t work.

    If you want actual numbers to appear in each point, you’ll need to define an actual “anchor” or “end” of each point, such as a period. If you can state that a . will appear only at the end of the point (ignoring the potential one that follows the leading-digit), you could use the following regex:

    \d+[.)\s][^.]*\.
    

    It can be dropped into the preg_match_all() from above just as easily:

    preg_match_all('/(\d+[.)\s][^.]*\.)/', $text, $matches);
    

    Regex explained:

    \d+        # leading number
    [.)\s]     # followed by a `.`, `)`, or whitespace
    [^.]*      # any non-`.` character(s)
    \.         # ending `.`
    

    The caveat with the second regex is that a . may only appear at the end of each point (and following the leading digit). However, I think that this rule may be easier to follow than the “no numbers in the point” rule – it all depends on your actual input though.

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

Sidebar

Related Questions

I'm looking for a good example of using Regular Expressions in PHP to reverse
I am looking to create an auto incrementing unique string using PHP, containing [a-Z
I'm simply looking to take the first csv out of a string, using PHP.
I'm looking for an example how to emulate XMLHttpRequest client using PHP. In other
I'm primarily a JS developer, using PHP for that server-side kick and I'm looking
Using PHP, I have a query that goes through my DB looking for pending
I'm looking to convert a file to a binary string, preferably using PHP. Is
Using PHP, is there a function/method/way to check if a variable contains something that
We are looking, the script that can easily replace the value using PHP DOM.
I'm looking into the feasibility of using PHP - instead of mod_rewrite - to

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.