tomb<blog>

musings from the dark side

Jun 30, 2009

Regex for Byte and Short

Jun 30, 2009

Took way too long to find the regex for byte, and I couldn't find one at all for a short (int16)

Did find this though. I love the internet machine sometimes...

Byte: 
(^(
    [0-9]|
    [1-9][0-9]|
    1[0-9][0-9]|
    2[0-4][0-9]|
    25[0-5]
)$);
Short: 
(^(-?
    [0-9]{1,4}|
    [12][0-9]{4}|
    3[01][0-9]{3}|
    32[0-6][0-9]{2}|
    327[0-5][0-9]|
    3276[0-7]|
    -3276[0-8]
)$);

 

I think the short one needs a little massaging. I still have to do one for int32, but I'm going to look for a better way to do numeric ranges with regular expressions.

Edit: Put regexes on separate lines.

 
Powered by Mango Blog All Content and Media © Copyright MMX
Tomb Multimedia Productions Ltd
All Rights Reserved