当前位置: 动力学知识库 > 问答 > 编程问答 >

Regex for HTTP User Agent

问题描述:

what Regex can be used to clear the HTTP User Agent of some of the information.

(I am actually interested in simplifying the user agent string in order to identify the device id for mobiles easier)

I would like to remove a string followed by a slash or a space and then digits and dots.

Slash before version

  • Mozilla/5.0
  • AppleWebKit/537.36
  • Chrome/31.0.1650.59
  • Safari/537.36

Space before version

  • Android 4.4.2
  • MSIE 10.0

Thanks,

Andrei

网友答案:

Try this regex:

 .+?[/\s][\d.]+

Description

Demo

http://regexr.com?37l4e

Discussion

You may notice that for this UA string there is more than 10 digits and dots. This is why I use [\d.]+.

分享给朋友:
您可能感兴趣的文章:
随机阅读: