@Test public void identifyOSXVersion_versionWithUnderlineAndRoundBracket() { final String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.5 Safari/534.55.3"; final VersionNumber v = VersionParser.identifyOSXVersion(userAgent); assertThat(v.toVersionString()).isEqualTo("10.7.3"); }
static VersionNumber identifyOSXVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\.\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?)\\)")); for (final Pattern pattern : patterns) { final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX).replaceAll("_", ".")); break; } } return version; }
VersionParser { static VersionNumber identifyOSXVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\.\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?)\\)")); for (final Pattern pattern : patterns) { final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX).replaceAll("_", ".")); break; } } return version; } }
VersionParser { static VersionNumber identifyOSXVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\.\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?)\\)")); for (final Pattern pattern : patterns) { final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX).replaceAll("_", ".")); break; } } return version; } private  VersionParser(); }
VersionParser { static VersionNumber identifyOSXVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\.\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?)\\)")); for (final Pattern pattern : patterns) { final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX).replaceAll("_", ".")); break; } } return version; } private  VersionParser(); static VersionNumber parseLastVersionNumber(@Nonnull final String text); static VersionNumber parseOperatingSystemVersion(@Nonnull final OperatingSystemFamily family, @Nonnull final String userAgent); static VersionNumber parseVersion(@Nonnull final String version); }
VersionParser { static VersionNumber identifyOSXVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\.\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?);")); patterns.add(Pattern.compile("Mac OS X\\s?((\\d+)((\\_\\d+)+)?)\\)")); for (final Pattern pattern : patterns) { final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX).replaceAll("_", ".")); break; } } return version; } private  VersionParser(); static VersionNumber parseLastVersionNumber(@Nonnull final String text); static VersionNumber parseOperatingSystemVersion(@Nonnull final OperatingSystemFamily family, @Nonnull final String userAgent); static VersionNumber parseVersion(@Nonnull final String version);  }