Skip to content

Instantly share code, notes, and snippets.

@Nimfadora
Created November 10, 2017 11:38
Show Gist options
  • Save Nimfadora/2d58b7a6c41a9ab4a7f3cf7c70e4602c to your computer and use it in GitHub Desktop.
Save Nimfadora/2d58b7a6c41a9ab4a7f3cf7c70e4602c to your computer and use it in GitHub Desktop.
private static final List<Pair<Pattern, String>> UA_PATTERN_TO_FRIENDLY_NAME = asList(
// IE
Pair.of(compile(""".*; MSIE ([.0-9]*);.*"""), "Internet Explorer"),
Pair.of(compile(""".*WOW64.*rv:([.0-9]*).*"""), "Internet Explorer"),
Pair.of(compile(""".*Trident.*rv:([.0-9]*).*"""), "Internet Explorer"),
Pair.of(compile(""".*IEMobile/([.0-9]*).*"""), "Internet Explorer Mobile"),
Pair.of(compile(""".*Windows Phone ([.0-9]*).*"""), "Internet Explorer Mobile"),
// Edge
Pair.of(compile(""".*EdgA/([.0-9]*).*"""), "Edge for Android"),
Pair.of(compile(""".*EdgiOS/([.0-9]*).*"""), "Edge for iOS"),
Pair.of(compile(""".*Edge/([.0-9]*).*"""), "Edge"),
// Android
Pair.of(compile(""".*Android.*(Chrome|CrMo)/([.0-9]*).*Safari.*"""), "Chrome for Android"),
Pair.of(compile(""".*Android.*Version/([.0-9]*).*Safari.*"""), "Android Browser"),
Pair.of(compile(""".*Android.*Firefox/([.0-9]*).*"""), "Firefox for Android"),
Pair.of(compile(""".*Android.*OPR/([.0-9]*).*"""), "Opera for Android"),
// Firefox
Pair.of(compile(""".*Mac OS X.*FxiOS/([.0-9]*).*"""), "Firefox for iOS"),
Pair.of(compile(""".*Firefox/([.0-9]*).*"""), "Firefox"),
Pair.of(compile(""".*Fennec/([.0-9]*).*"""), "Firefox"),
// Opera
Pair.of(compile("""Opera/.*(Opera Mobi|Opera Tablet|Opera Mini)/([.0-9]*).*"""), "Opera Mobile"),
Pair.of(compile(""".*Mac OS X.*OPiOS/([.0-9]*).*"""), "Opera for iOS"),
Pair.of(compile(""".*(OPR|Opera).* VERSION/([.0-9]*).*"""), "Opera"),
Pair.of(compile(""".*Opera ([.0-9]*).*"""), "Opera"),
Pair.of(compile(""".*OPR/([.0-9]*).*"""), "Opera"),
Pair.of(compile("""Opera/([.0-9]*).*"""), "Opera Standard"),
// YaBrowser
Pair.of(compile(""".*YaBrowser/([.0-9]*).*"""), "YaBrowser"),
// Chrome
Pair.of(compile(""".*Chrome/([.0-9]*).*"""), "Chrome"),
Pair.of(compile(""".*Mac OS X.*CriOS/([.0-9]*).*"""), "Chrome for iOS"),
// other iOs
Pair.of(compile(""".*iPad.*Version/([.0-9]*).*"""), "Safari iOS"),
Pair.of(compile(""".*iPhone.*Version/([.0-9]*).*"""), "Safari iOS"),
Pair.of(compile(""".*Macintosh.*Version/([.0-9]*).*"""), "Safari macintosh"),
Pair.of(compile(""".*iPhone.*GSA/([.0-9]*).*"""), "Google Search iOS"),
Pair.of(compile(""".*iPad.*GSA/([.0-9]*).*"""), "Google Search iOS"),
Pair.of(compile(""".*iPhone.*FBAN/FBIOS;FBAV/([.0-9]*).*"""), "Facebook app for iOs"),
Pair.of(compile(""".*iPad.*FBAN/FBIOS;FBAV/([.0-9]*).*"""), "Facebook app for iOs"),
Pair.of(compile("""(.*)"""), UNKNOWN)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment