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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:37:07+00:00 2026-05-24T18:37:07+00:00

I got decimal problem while I parsing my command. 12.90 has been parsed wrongly:

  • 0

I got decimal problem while I parsing my command. 12.90 has been parsed wrongly:

// My command
$cmd = 'CREATE product price:12.90, name: "Create me"';

// My parser
preg_match_all('/\w+|".*?"|(?!\s)\W/', $cmd, $list);

Output:

Array
    (
        [0] => CREATE
        [1] => product
        [2] => price
        [3] => :
        [4] => 12 // << problem starts here
        [5] => .
        [6] => 90
        [7] => ,
        [8] => name
        [9] => :
        [10] => "Create me"
    )

I am looking for this output:

Array
    (
        [0] => CREATE
        [1] => product
        [2] => price
        [3] => :
        [4] => 12.90 // supposed
        [5] => ,
        [6] => name
        [7] => :
        [8] => "Create me"
    )

So, how can I solve this problem?

Edit: (the better solution)

Guys, I accepted Jesse’s answer according to my question. But I realized it is not good enough for my complex commands. It’s better, because it works with both decimals like 12.90 and alias names like p.price. So just look at my example and parser below for it. I hope this help someone.

// My command
$cmd = 'GET `order` -o, product -p 
           LIST o.user_id, o.product_id, p.name, p.price
           REL o.order_id = 3 AND p.price > 12.90'; 

// My complex command:
preg_match_all('/[0-9_\.]+|\w+|".*?"|`.*?`|\'.*?\'|!=|<=|>=|(?!\s)\W/', $cmd, $list); 

// Output:  
Array
(
[0] => Array
    (
        [0] => GET
        [1] => `order`
        [2] => -
        [3] => o
        [4] => ,
        [5] => product
        [6] => -
        [7] => p
        [8] => LIST
        [9] => o
        [10] => .
        [11] => user_id
        [12] => ,
        [13] => o
        [14] => .
        [15] => product_id
        [16] => ,
        [17] => p
        [18] => .
        [19] => name
        [20] => ,
        [21] => p
        [22] => .
        [23] => price
        [24] => REL
        [25] => o
        [26] => .
        [27] => order_id
        [28] => =
        [29] => 3
        [30] => AND
        [31] => p
        [32] => .
        [33] => price
        [34] => >
        [35] => 12.90
    )

)
  • 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-24T18:37:07+00:00Added an answer on May 24, 2026 at 6:37 pm

    \w class does not include the . so the “quick” fix is to add it as follows:

      preg_match_all('/[\w.]+|".*?"|(?!\s)\W/', $cmd, $list);
    

    Do you have any other requirements regarding where the period is allowed? (ie only matching when it is between numbers?). If so, you may need to make the matching more specialized.

    The biggest thing thing that jumps out at me is if the period would be used as delimiter for some other aspect of your parser. If the RE that you gave is your entire parser you are probably ok.

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

Sidebar

Related Questions

I got a decimal property, like [XmlElementAttribute(DataType = decimal)] decimal Price The problem is
I've got a problem that seems simple on the face of it but has
I've managed to create an optional decimal element using this: <xs:simpleType name=OptionalDecimal> <xs:union memberTypes=xs:decimal
I've got some entities which have decimal properties on them. These entities' properties are
How do I split a number by the decimal point in php? I've got
Got a bluescreen in windows while cloning a mercurial repository. After reboot, I now
Got a problem with ADOMD.NET 8.0, SQL2008 and our app. It isn't giving us
Got a requirement to rebuild mssql full-text index. Problem is - I need to
I've got a database using DECIMAL type values for various tests on crude oil.
Guys, I have a string that contains a decimal number. The problem is, sometimes

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.