List of usage examples for java.util.regex Matcher group
public String group(String name)
From source file:edu.umn.msi.tropix.proteomics.conversion.DtaNameUtils.java
public static DtaNameSummary getDtaNameSummary(final String filename) { final Matcher matcher = DTA_PATTERN.matcher(FilenameUtils.getName(filename)); matcher.matches();// w w w . j av a2 s. com final String basename = matcher.group(1); final int start = Integer.parseInt(matcher.group(2)); final int end = Integer.parseInt(matcher.group(3)); final short charge = Short.parseShort(matcher.group(4)); return new DtaNameSummary(basename, start, end, charge); }
From source file:io.redlink.sdk.util.ApiHelper.java
/** * Build a proper api version/* w ww .j ava 2 s . com*/ * * @param version raw version * @return api version * @see <a href="http://dev.redlink.io/sdk#introduction">api/sdk versioning</a> */ public static String getApiVersion(String version) { if (StringUtils.isBlank(version)) { return null; } else { final Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) { if (StringUtils.isBlank(matcher.group(4))) { return String.format("%s.%s", matcher.group(1), matcher.group(2)); } else { return String.format("%s.%s-%s", matcher.group(1), matcher.group(2), matcher.group(4)); } } else { return null; } } }
From source file:Main.java
/** * Parses an xs:duration attribute value, returning the parsed duration in milliseconds. * * @param value The attribute value to parse. * @return The parsed duration in milliseconds. *//* w ww.ja va2s. c o m*/ public static long parseXsDuration(String value) { Matcher matcher = XS_DURATION_PATTERN.matcher(value); if (matcher.matches()) { boolean negated = !TextUtils.isEmpty(matcher.group(1)); // Durations containing years and months aren't completely defined. We assume there are // 30.4368 days in a month, and 365.242 days in a year. String years = matcher.group(3); double durationSeconds = (years != null) ? Double.parseDouble(years) * 31556908 : 0; String months = matcher.group(5); durationSeconds += (months != null) ? Double.parseDouble(months) * 2629739 : 0; String days = matcher.group(7); durationSeconds += (days != null) ? Double.parseDouble(days) * 86400 : 0; String hours = matcher.group(10); durationSeconds += (hours != null) ? Double.parseDouble(hours) * 3600 : 0; String minutes = matcher.group(12); durationSeconds += (minutes != null) ? Double.parseDouble(minutes) * 60 : 0; String seconds = matcher.group(14); durationSeconds += (seconds != null) ? Double.parseDouble(seconds) : 0; long durationMillis = (long) (durationSeconds * 1000); return negated ? -durationMillis : durationMillis; } else { return (long) (Double.parseDouble(value) * 3600 * 1000); } }
From source file:com.bstek.dorado.util.clazz.TypeInfo.java
public static TypeInfo parse(String className) throws ClassNotFoundException { if (StringUtils.isEmpty(className)) { return null; }// ww w . jav a2 s .co m String typeName = null; boolean aggregated = false; Matcher matcher = AGGREGATION_PATTERN_1.matcher(className); if (matcher.matches()) { typeName = matcher.group(2); aggregated = true; } else { matcher = AGGREGATION_PATTERN_2.matcher(className); if (matcher.matches()) { typeName = matcher.group(1); aggregated = true; } } if (typeName == null) { typeName = className; } return new TypeInfo(ClassUtils.forName(typeName), aggregated); }
From source file:Main.java
private static int attemptMode() { String output = attemptCommand(new String[] { "mode", "con" }); if (output == null) { return 80; }/*w w w . java 2s . c o m*/ Pattern pattern = Pattern.compile("Columns:[ \t]*(\\d+)"); Matcher m = pattern.matcher(output); if (!m.find()) { return 80; } return Integer.parseInt(m.group(1)); }
From source file:com.magnet.plugin.helpers.UrlParser.java
/** * @param url url where path param are expanded (removed "{""}") * @return expanded url//from w ww .j a va2 s .c o m */ public static String expandUrl(String url) { Matcher m = PATH_PARAM_PATTERN.matcher(url); while (m.find()) { String paramDef = m.group(1); String[] paramParts = paramDef.split(":"); if (paramParts.length > 1) { url = url.replaceAll(Rest2MobileConstants.START_TEMPLATE_VARIABLE_REGEX + paramParts[0] + Rest2MobileConstants.END_TEMPLATE_VARIABLE_REGEX, paramParts[1]); } else { url = url.replaceAll(Rest2MobileConstants.START_TEMPLATE_VARIABLE_REGEX + paramParts[0] + Rest2MobileConstants.END_TEMPLATE_VARIABLE_REGEX, paramParts[0]); } } return url; }
From source file:hoot.services.utils.PostgresUtils.java
static Map<String, String> parseTags(String tagsStr) { Map<String, String> tagsMap = new HashMap<>(); if ((tagsStr != null) && (!tagsStr.isEmpty())) { Pattern regex = Pattern.compile("(\"[^\"]*\")=>(\"(?:\\\\.|[^\"\\\\]+)*\"|[^,\"]*)"); Matcher regexMatcher = regex.matcher(tagsStr); while (regexMatcher.find()) { String key = regexMatcher.group(1); key = StringUtils.removeStart(key, "\""); key = StringUtils.removeEnd(key, "\""); String val = regexMatcher.group(2); val = StringUtils.removeStart(val, "\""); val = StringUtils.removeEnd(val, "\""); tagsMap.put(key, val); }/*from w w w . j av a2 s.co m*/ } return tagsMap; }
From source file:io.github.carlomicieli.footballdb.starter.mapping.Height.java
private static Optional<Height> extractValue(String value, Pattern p) { Matcher m = p.matcher(value); if (m.find()) { int f = Integer.parseInt(m.group(1)); int i = Integer.parseInt(m.group(2)); return Optional.ofNullable(new Height(f, i)); }/*from w w w . ja va 2s . co m*/ return Optional.empty(); }
From source file:Main.java
public static int[] parseIntegerList(String list, int minValue, int maxValue) { ArrayList tmpList = new ArrayList(); Pattern p = Pattern.compile("(\\d*)-(\\d*)"); String[] a = list.replace(',', ' ').split("\\s+"); int i = a.length; for (int i$ = 0; i$ < i; ++i$) { String token = a[i$];//www . j a v a 2 s . c o m try { if (token.matches("\\d+")) { tmpList.add(Integer.valueOf(Integer.parseInt(token))); } else { Matcher e = p.matcher(token); if (e.matches()) { String a1 = e.group(1); String b = e.group(2); int min = a1.equals("") ? minValue : Integer.parseInt(a1); int max = b.equals("") ? maxValue : Integer.parseInt(b); for (int i1 = min; i1 <= max; ++i1) { tmpList.add(Integer.valueOf(i1)); } } } } catch (NumberFormatException var15) { ; } } if (minValue <= maxValue) { int var16 = 0; while (var16 < tmpList.size()) { if (((Integer) tmpList.get(var16)).intValue() >= minValue && ((Integer) tmpList.get(var16)).intValue() <= maxValue) { ++var16; } else { tmpList.remove(var16); } } } int[] var17 = new int[tmpList.size()]; for (i = 0; i < var17.length; ++i) { var17[i] = ((Integer) tmpList.get(i)).intValue(); } return var17; }
From source file:io.cloudslang.lang.cli.SlangBootstrap.java
private static Set<String> findPropertyReferences(String value) { Matcher mather = SUBSTITUTION_PATTERN.matcher(value); Set<String> variableNames = new HashSet<>(); while (mather.find()) { variableNames.add(mather.group(1)); }//from ww w . jav a 2s.com return variableNames; }