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

    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Simple RegEx Pattern- Im half way there


    Hi All

    Need a little help with my RegEx, I am half way there but can't figure out the last bit

    I want the Regex to match.

    123-456-789

    I don't mind how long the numbers are, but the dashes in the middle can only be 1 long

    My regex so far
    ([^-]([0-9]+[^-]))

    This matches
    123-456-789
    but will also match
    123-456----789

    I just need the Regex to only allow 1 dash in the middle

    Thanks for any help
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,745
    Rep Power
    9397
    It needs to match against numbers, maybe followed by a hyphen and more numbers, maybe followed by a hyphen and more numbers...
    Code:
    ^\d+(-\d+)*$

IMN logo majestic logo threadwatch logo seochat tools logo