1

I need to parse apart blackberry browser user agents so I can get what device and version it is using python 2.5. For example:

BlackBerry9630/4.7.1.65 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/-1,gzip(gfe),gzip(gfe)

In the above user agent I would like to gather the following groups:

Browser: Blackberry 
Device: 9630 
Major Version: 4 
Minor Version: 7

The rest of the info I don't care about.

Here is another example:

BlackBerry9530/5.0.0.328 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/105,gzip(gfe),gzip(gfe),gzip(gfe)
Browser: Blackberry
Device: 9530
Major Version: 5
Minor Version: 0

I'm horrible at figuring out regex and any help would be great. Thanks

0

3 Answers 3

1

Something like this will work for your case, but not necessarily all cases:

'^(\D*)(\d*)/(\d*)\.(\d*)\.'

\D means "any character that's not a decimal digit", and \d means "any decimal digit".

Sign up to request clarification or add additional context in comments.

Comments

0
browser, version = useragent.split()[0].split("/")
browsername = re.findall(r"[a-zA-Z]+", browser)
device = re.findall(r"[0-9]+", browser)
versions = re.findall(r"[0-9]+", version)
major = versions[0]
minor = versions[1]

Comments

0
>>> import re
>>> s = 'BlackBerry9530/5.0.0.328 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/105,gzip(gfe),gzip(gfe),gzip(gfe)'
>>> print(re.compile(r'(Blackberry)(\d+)/(\d+)\.(\d+)\.',re.I).search(s).groups())
('BlackBerry', '9530', '5', '0')
>>>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.