This regex will match 2 and 3 segments like 4.0 or 6.1.3
/\b[0-9]+_[0-9]+(?:_[0-9]+)?\b/
Javascript Example:
> navigator.userAgent
"Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146"
> navigator.userAgent.match(/\b[0-9]+_[0-9]+(?:_[0-9]+)?\b/);
["6_1_2"]
Note that this may also match other devices, so make sure you test this on a iOS device.
This will return the OS X version on a Mac.
> navigator.userAgent
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1"
> navigator.userAgent.match(/\b[0-9]+_[0-9]+(?:_[0-9]+)?\b/);
["10_8_4"]
You also may want to replace the _ by . using .replace(/_/g,'.'); or even convert it to a array using .split('_');.
_iOSDevice = !!navigator.platform.match(/iPhone|iPod|iPad/);
if(_iOSDevice)
_iOSVersion = (navigator.userAgent.match(/\b[0-9]+_[0-9]+(?:_[0-9]+)?\b/)||[''])[0].replace(/_/g,'.');