What is the regular expression used to match the UserAgent of all browsers and the main search engine spider?

Source: Internet
Author: User
To use PHP to implement the UA whitelist, you must be able to match the regular expressions of basically all browsers and major search engine spider UA. This problem may be complicated. let's see if anyone can solve it. To use PHP to implement the UA whitelist, you must be able to match the regular expressions of basically all browsers and major search engine spider UA.
This problem may be complicated. let's see if anyone can solve it.

Reply content:

To use PHP to implement the UA whitelist, you must be able to match the regular expressions of basically all browsers and major search engine spider UA.
This problem may be complicated. let's see if anyone can solve it.

var userAgent = navigator.userAgent.toLowerCase();// Figure out what browser is being usedjQuery.browser = {    version: (userAgent.match( /.+(?:rv|it|ra|ie)[/: ]([d.]+)/ ) || [])[1],    safari: /webkit/.test( userAgent ),    opera: /opera/.test( userAgent ),    msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),    mozilla: /mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)};

For your reference, http://www.bkjia.com/jQuery/449138.html
Improve the thinking of the other two clues,
1. in the earliest implementation of jQuery, UA detection seems to be based on regular expression detection, and later compatibility code uses the "test" method;
2. JavaScript advanced programming, with such code in mind. the sample code of the third edition is on page 233.

Add:
This site can find the vast majority of browsers and search engine spider UA: http://www.useragentstring.com/pages/useragentstring.php
Ie ua description: https://msdn.microsoft.com/en-us/library/ms537503 (v = vs.85). aspx
FireFox UA description: https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent
Chrome UA description: https://developer.chrome.com/multidevice/user-agent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.