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

    Join Date
    Oct 2007
    Posts
    19
    Rep Power
    0

    Pattern Matching For Date and Long/Lati


    Need help...
    in pattern matching for Date(mm/dd/yy , dd/mm/yy)and latitude/longitude
    I have tried as bellow but date will be matched as lat/lng because of delimiter "/"
    Date should have delimiter as [/ - ] and lat/long should have [ , : ; /]
    dbarray=( 8/Dec/2010@@@456/1145@@@-@@@- )
    for i in ${dbarray[@]}; do
    if [[ $i =~ ^({(0[1-9]|1[012]|\D)\.(0[1-9]|[12][0-9]|3[01])\.(19/20)[0-9]+$})|^({(0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012]|\D)\.(19|20)[0-9]+$}) ]]; then
    Installer=$i
    elif [[ $i =~ (^[0-9]+).+([0-9]+)$ ]]; then
    lat_lng=$i
    fi
    done
    Can anybody help me out from this... to test Date and long/latitude correctly !
    Thanks,
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,394
    Rep Power
    1688
    Your requirement is ... well, horrible! Matching dates is bad enough without rolling in the fact that you'll accept dd/mm as well as mm/dd, with the month component also being an alpha abbreviation and the day having, or not, a leading zero.
    I made a start, but gave up when my eyes started bleeding from trying to match up all the brackets as I started to build up the needed regex: and that was until (but not including the first year field!).
    Don't try and be clever is my suggestion - go for basic checks and assume that the data is good, so look for 1 or 2 numerics, followed by a / or -, then one or two numerics (or 3 alpha) followed by a / or -, then 2 or 4 numerics and assume if that pattern matches it's a date, and so on.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo