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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:51:24+00:00 2026-06-07T13:51:24+00:00

There is a string variable containing number data with dots , say $x =

  • 0

There is a string variable containing number data with dots , say $x = "OP/1.1.2/DIR"; . The position of the number data may change at any circumstance by user desire by modifying it inside the application , and the slash bar may be changed by any other character ; but the dotted number data is mandatory. So how to extract the dotted number data , here 1.1.2, from the string ?

  • 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-07T13:51:27+00:00Added an answer on June 7, 2026 at 1:51 pm

    Use a regular expression:

    (\d+(?:\.\d+)*)
    

    Breakdown:

    • \d+ look for one or more digits
    • \. a literal decimal . character
    • \d+ followed by one or more digits again
    • (...)* this means match 0 or more occurrences of this pattern
    • (?:...) this tells the engine not to create a backreference for this group (basically, we don’t use the reference, so it’s pointless to have one)

    You haven’t given much information about the data, so I’ve made the following assumptions:

    • The data will always contain at least one number
    • The data may contain only a number without a dot
    • The data may contain multi-digit numbers
    • The numbers themselves may contain any number of dot/digit pairs

    If any of these assumptions are incorrect, you’ll have to modify the regular expression.

    Example usage:

    $x = "OP/1.1.2/DIR";
    
    if (!preg_match('/(\d+(\.\d+)*)/', $x, $matches)) {
        // Could not find a matching number in the data - handle this appropriately
    } else {
        var_dump($matches[1]); // string(5) "1.1.2"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a string variable containing number data , say $x = OP/12/DIR; .
I have a string variable, containing XML data and I was wondering if there
There is a String variable containing ascii characters and double bytes characters(for example, the
If I have a variable containing a string, is there a way that I
I have a string containing an environment variable, e.g. my_path = '$HOME/dir/dir2' I want
I have a variable in javascript containing a string of XML data that I
Is there a way to insert a string in a string constant/variable that contains
Given a variable which holds a string is there a quick way to cast
Is there a way to refer to a Javascript variable with a string that
let's say I have a variable containing an integer or a float (since integers

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.