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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:09:59+00:00 2026-06-11T06:09:59+00:00

Possible Duplicate: Retrieving numeric characters from a string I have a string like this

  • 0

Possible Duplicate:
Retrieving numeric characters from a string

I have a string like this –

[ [ -2, 1/2 ], // 1/2 represents one half

I want to retrieve the numeric characters and put them into an array that will end up looking like this:

array(
  [0] => -2,
  [1] => 1/2
)

What is the best way of doing this?

A more thorough example –

[ [ -2, 1/2, 4, 8 ],
  [ 5,  1/2, 1, -4/3 ],
  [ -2, 7/2, 4, 4 ],
  [ -2, 1/2, -3, 2 ] ]

I am going through this matrix line by line and I want to extract the numbers into an array for each line.

This question is very similar to a question I asked before – Retrieving numeric characters from a string

The difference is that there are no decimal points in the numbers. Instead non-integers are represented as fractions.

  • 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-11T06:10:00+00:00Added an answer on June 11, 2026 at 6:10 am

    Try to deal with preg syntax. Your preg expression is simple: /(-?\d+(?:\/\d+)?)/.

    preg_match_all( '/(-?\d+(?:\/\d+)?)/', $string, $matches);
    
    // given :
    $str = '[ [ -2, 1/2, 4, 8 ],
      [ 5,  1/2, 1, -4/3 ],
      [ -2, 7/2, 4, 4 ],
      [ -2, 1/2, -3, 2 ] ]';
    
    // outut :
    $matches = array (
      0 => 
      array (
        0 => '-2',
        1 => '1/2',
        2 => '4',
        3 => '8',
        4 => '5',
        5 => '1/2',
        6 => '1',
        7 => '-4/3',
        8 => '-2',
        9 => '7/2',
        10 => '4',
        11 => '4',
        12 => '-2',
        13 => '1/2',
        14 => '-3',
        15 => '2',
      ),
      1 => 
      array (
        0 => '-2',
        1 => '1/2',
        2 => '4',
        3 => '8',
        4 => '5',
        5 => '1/2',
        6 => '1',
        7 => '-4/3',
        8 => '-2',
        9 => '7/2',
        10 => '4',
        11 => '4',
        12 => '-2',
        13 => '1/2',
        14 => '-3',
        15 => '2',
      ),
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Retrieving the top 100 numbers from one hundred million of numbers I
Possible Duplicate: Retrieving the calling method name from within a method (C#) I have
Possible Duplicate: Retrieving the last record in each group I have two tables set
Possible Duplicate: Retrieving the latest note (by timestamp) in a single query from a
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: remove multiple whitespaces in php I have a stream of characters, a
Possible Duplicate: Retrieving python module path Suppose I have code in 3 python files.
Possible Duplicate: Problem in datareader retrieving data I have Memberships and Bookings tables in
Possible Duplicate: How to pass object from one activity to another in Android While
Possible Duplicate: Retrieving Android API version programmatically I am trying to retrieve the current

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.