I am trying to create a regex for the following UA string:
Mozilla/5.0 (BlackBerry; U; BlackBerry 9850; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.115 Mobile Safari/534.11+
I want to know if the device is a Blackberry 5.0 so I can create a non ajax jquery mobile site.
I can get the Mozilla/5.0 bit ok but im really struggling to match the word Blackberry.
Can anyone help?
According to this administrator’s Blackberry Support Community Forums Post, AJAX support for BlackBerry phones was released with version 4.6
According to this list, BlackBerry UA Strings have always contained the word BlackBerry, have usually contained the phone model number, and have always contained a version number:
the version number comes either after the word
BlackBerry, possibly a model number consisting of numbers and letters, then a forward slash (/), or it comes well after the wordBlackBerry, but immediately following the stringVersion/Using this expression:
In a find-type regular expression parser (like PHP’s
preg_match(), .Net’sRegex.Match(), or Java’smatcher.find()functions) this expression will allow discerning between a version number from0.0.Xto4.5.Xand a version number from4.6.XtoX.X.XwhereXrepresents any number not previously matched.What’s that now? Sorry… in other words, using that regex against a user agent string should allow you to determine whether it’s a BlackBerry browser or not AND whether the version number indicates support for AJAX (pseudo-code):
Summary: Match group #1 (could be made optional) matches the part between
BlackBerryand any matched version number. Group #2 matches the version number. Group #3 contains the version number if it is0.0.Xto4.5.X. Group #4 contains the version number if it is4.6.Xor greater, if it only consists of digits and decimal points. If the version does not seem to match this convention, possibly if there are letters or underscores as well, then it will be captured into Group #5.I think this is all you need (once translated into whichever language you are using). The expression should be supported by .Net, Java, PHP, or even JavaScript if necessary.