List of usage examples for java.util.regex Matcher group
public String group(String name)
From source file:com.netflix.genie.agent.AgentMetadataImpl.java
private static String getAgentPidOrFallback() { final String jvmId = ManagementFactory.getRuntimeMXBean().getName(); final Matcher pidPatternMatcher = Pattern.compile("(\\d+)@.*").matcher(jvmId); if (pidPatternMatcher.matches() && !StringUtils.isBlank(pidPatternMatcher.group(1))) { return pidPatternMatcher.group(1); }/* ww w .j av a 2s.c o m*/ log.warn("Failed to retrieve agent PID (JVM id: {})", jvmId); return FALLBACK_STRING; }
From source file:com.liveramp.cascading_ext.flow_step_strategy.RenameJobStrategy.java
private static String getCanonicalName(String name) { Matcher matcher = TEMP_PIPE_NAME.matcher(name); if (matcher.matches()) { return matcher.group(1); } else {/*from ww w . j a v a 2 s . c om*/ return name; } }
From source file:fi.hsl.parkandride.core.domain.prediction.PredictionRequest.java
static Duration parseRelativeTime(String relativeTime) { Matcher matcher = java.util.regex.Pattern.compile(HHMM_PATTERN).matcher(relativeTime); if (matcher.matches()) { int hours = parseOptionalInt(matcher.group(2)); int minutes = Integer.parseInt(matcher.group(3)); return standardHours(hours).plus(standardMinutes(minutes)); } else {// w ww .j av a 2s .co m return Duration.ZERO; } }
From source file:org.mitre.jdbc.datasource.util.SqlFileParser.java
private static String getFirstWord(String line) { Matcher match = WORD_PATTERN.matcher(line); return match.find() ? match.group(1) : null; }
From source file:com.google.code.rptm.metadata.pmc.CommitteeInfoParser.java
public static void parse(InputStream in, CommitteeInfoVisitor visitor) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); int state = STATE_PREAMBLE; int i = 0;/*ww w . j a va 2s . c om*/ while (true) { String line = reader.readLine(); i++; if (line == null) { if (state != STATE_COMPLETE) { throw new IOException("Unexpected end of file (state = " + state); } else { break; } } else if (state != STATE_PREAMBLE && END_MARKER.matcher(line).matches()) { if (state == STATE_PROJECT) { visitor.endProject(); } state = STATE_COMPLETE; continue; } else if ((state == STATE_PROJECT || state == STATE_PROJECT_COMPLETE) && StringUtils.isBlank(line)) { if (state == STATE_PROJECT) { visitor.endProject(); state = STATE_PROJECT_COMPLETE; } continue; } else if (state == STATE_PROJECT) { Matcher m = MEMBER_ENTRY.matcher(line); if (m.matches()) { visitor.member(m.group(1), m.group(3)); continue; } } else if (state == STATE_PREAMBLE || state == STATE_PROJECT_COMPLETE) { Matcher m = PROJECT_HEADER.matcher(line); if (m.matches()) { visitor.startProject(m.group(1)); state = STATE_PROJECT; continue; } else if (state == STATE_PREAMBLE) { continue; } } else if (state == STATE_COMPLETE && StringUtils.isBlank(line)) { continue; } throw new IOException("Unexpected content at line " + i + " (state = " + state + "): " + line); } }
From source file:com.spartasystems.holdmail.mime.MimeUtils.java
/** * Strip any leading/trailing spaces from the string. Spaces inside the quotes will be maintained. * <ul>/*from w ww .j ava2 s .c o m*/ * <li>null --> null</li> * <li>"" --> ""</li> * <li>" blah " -> "blah"</li> * <li>" \"blah\" " -> "blah"</li> * <li>" \" blah \" " -> " blah "</li> * </ul> * @param input the input string * @return The trimmed string */ public static String trimQuotes(final String input) { if (StringUtils.isBlank(input)) { return input; } final Pattern TRIM_PARAM_REGEX = Pattern.compile("^\\s*\"?(?<value>.*?)\"?\\s*$"); Matcher matcher = TRIM_PARAM_REGEX.matcher(input); if (matcher.matches()) { return matcher.group("value"); } else { return input; } }
From source file:net.gcolin.simplerepo.maven.Resolver.java
public static String resolve(String value, Properties props, Model model) { if (value == null) { return null; }/*from ww w .j a va 2s .c om*/ Matcher matcher = VAR_PATTERN.matcher(value); StringBuffer result = new StringBuffer(); while (matcher.find()) { String expr = matcher.group(1); if (props.containsKey(expr)) { matcher.appendReplacement(result, props.getProperty(expr)); } else { if (expr.startsWith("project.")) { expr = expr.substring(8); } try { matcher.appendReplacement(result, String.valueOf(BeanUtils.getProperty(model, expr))); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalArgumentException(e); } } } matcher.appendTail(result); return result.toString(); }
From source file:Main.java
public static int getLengthOfLongestWord(String string) { int longestWordLength = 0; Matcher m = Pattern.compile("\\s*(\\S+)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(string); while (m.find()) { longestWordLength = Math.max(longestWordLength, m.group(1).length()); }// w w w. j ava 2 s.c o m return longestWordLength; }
From source file:cn.vlabs.duckling.common.http.WebSite.java
private static Map<String, String> extractParams(String query) { Map<String, String> params = new HashMap<String, String>(); Pattern p = Pattern.compile("([^&]+)=([^&]+)"); Matcher m = p.matcher(query); while (m.find()) { String key = m.group(1).trim(); if (key.length() > 0) { params.put(key, m.group(2)); }//from ww w .ja v a 2 s . com } return params; }
From source file:com.cognifide.cq.cqsm.core.scripts.ScriptUtils.java
public static String parseCommand(String command, Map<String, String> definitions) throws ActionCreationException { command = StringUtils.strip(command); Set<String> definitionNames = new HashSet<>(); Matcher matcher = DEFINITION.matcher(command); while (matcher.find()) { String definitionName = matcher.group(1); definitionNames.add(definitionName); }/*from w w w. j ava 2 s . c om*/ for (String definitionName : definitionNames) { if (definitions == null) { throw new ActionCreationException("Definitions map is not specified"); } String definitionValue = definitions.get(definitionName); if (definitionValue == null) { throw new ActionCreationException("Definition " + definitionName + " not found"); } command = StringUtils.replace(command, String.format("${%s}", definitionName), definitionValue); } return command; }