1
I’m trying to create a regex ( to use in PHP ) that can match the groups correctly and extract the information I need. In this case is to get information from android useragent.
When the useragent is like this:
User-Agent: Mozilla/5.0 (Linux; Android 5.0.2; SM-G530BT Build/LRX22G; wv) Applewebkit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/56.0.2924.87 Mobile Safari/537.36
certain, but has useragent that has an extra die, the "en" , like this:
User-Agent: Mozilla/5.0 (Linux; U; Android 4.1.2; en; LG-E467f Build/JZO54K) Applewebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
I couldn’t because the "en" is optional.
Follow what I’ve tried https://regex101.com/r/6TRsM2/1
my regex is this:
(?P<browser>Android)\s(?P<major_version>\d+)\.(?P<minor_version>\d+\.?\d?);(?P<lang>\spt-br)?(?P<device>[ \w\-?]+)\s
Can someone help me finish this regex? and I need it to marry all the groups, and when I don’t have the en, just come back empty.
You’re right, I didn’t remember what other languages might come from or even another user agent structure. The ideal was one that would marry any lang that came. But in the moment, for what I need it worked. Thank you.
– Caio Maia