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

    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Find a number pattern in a string


    Hi
    I am a bit new to using Regex an am trying to create an expression that finds a varying set of numbers in a string, the number format would be something like the cat sat on {numbers} Mats
    The Number format can be
    NN NN
    To
    NNNNN NNNNN where N is a number or a ? So for example
    12 34
    12?? 34??
    12345 12345

    the separator in between the numbers Blocks is either a whitespace an . or a -
    I have come up with the following -
    [\d\t .?-]{4,}

    Which seems to pick most of the combinations, however if the a 3 digit no has a preceeding space this is also counted. Is there anyway to exclude the preceding space or is there a better way to achieve my goal.
    I am trying to achive this using PCRE

    Thanks

    Mee
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    Always a pair of numbers? Then write your expression to get a pair of numbers.
    Code:
    (\d+\?*)[\s.-]+(\d+\?*)

IMN logo majestic logo threadwatch logo seochat tools logo