I am trying to make a mobile detection class that is supposed to strip the user agent to a simple basic string like this:
Output:
Mozilla/5.0 (*Linux x86_64*) AppleWebKit/* (KHTML, like
Gecko) Chrome/* Safari/*
from this:
Input: (HTTP_USER_AGENT)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko)
Chrome/24.0.1312.69 Safari/537.17
I am using this: /[0-9.-]{4,}/i pattern to strip the numbers and I get:
RESULT OF WHERE AM I SO FAR WITH ABOVE PATTERN:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/* (KHTML, like Gecko)
Chrome/* Safari/*
but my problem is how to remove the X11; I want a pattern that will remove everything everything after the first opening bracket and till the first empty space I think it is the right way. Acceptable alternative will be to be able to remove the brackets at all with a pattern.
Any suggestions?
PS: I am needing this to solve a problem with mobile detection and the dependency on browscap. So please no downvotes please!
PS2: the main purpose of this is to detect mobile clients and a desktop. after that I will tweak it to give information for the OS, and etc..
Replace X11; but not KHTML:
Explained demo here: http://regex101.com/r/vL6gT1