#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Digits and decimal points


    Hello everyone, I'm having an issue with decimal points and my Regex.

    Lets say I have something like:
    [21,[10355.0,8039.48,0.00895691]]

    I use the regex
    Code:
    \[(\d+)\,\[(-?\d+)\.\d+\,(-?\d+)\.\d+,([\d|.|-]+)\]\]
    which works just fine, however when I have something like:
    [21,[10355,8039.48,0.00895691]]
    that does not have a decimal point in one of the digit groups I don't get any matches.

    Can someone please help me with my number capture groups to also allow for a group without a decimal point..
    Thanks
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,191
    Rep Power
    9398
    So don't require the decimal point. If you're confident that the numbers themselves are valid,
    Code:
    [\d.]+
    If not then make the fractional part optional.
    Code:
    \d+(\.\d+)?

IMN logo majestic logo threadwatch logo seochat tools logo