List of usage examples for java.util.regex Matcher group
public String group()
From source file:ch.systemsx.cisd.openbis.generic.shared.translator.FilterTranslator.java
static Set<String> extractColumns(String expression) { Pattern parameterPattern = Pattern.compile(COLUMN_PATTERN); Set<String> list = new HashSet<String>(); Matcher matcher = parameterPattern.matcher(expression); while (matcher.find()) { String group = matcher.group(); list.add(group.substring(4, group.length() - 1)); }/* ww w. j a v a 2 s . c o m*/ return list; }
From source file:ch.systemsx.cisd.openbis.generic.shared.translator.FilterTranslator.java
static Set<String> extractParameters(String expression) { Pattern parameterPattern = Pattern.compile(PARAMETER_PATTERN); Set<String> list = new HashSet<String>(); Matcher matcher = parameterPattern.matcher(expression); while (matcher.find()) { String group = matcher.group(); list.add(group.substring(2, group.length() - 1)); }/* w w w .j a v a 2 s . co m*/ return list; }
From source file:Main.java
public static String camelCaseToSnakeCase(String camelCase) { List<String> tokens = new ArrayList<>(); Matcher matcher = PATTERN.matcher(camelCase); String acronym = ""; while (matcher.find()) { String found = matcher.group(); if (found.matches("^[A-Z]$")) { acronym += found;/*from w w w.j ava2 s . c o m*/ } else { if (acronym.length() > 0) { // we have an acronym to add before we continue tokens.add(acronym); acronym = ""; } tokens.add(found.toLowerCase()); } } if (acronym.length() > 0) { tokens.add(acronym); } if (tokens.size() > 0) { StringBuilder sb = new StringBuilder(tokens.remove(0)); for (String s : tokens) { sb.append("_").append(s); } return sb.toString(); } else { return camelCase; } }
From source file:Main.java
public static String camelCaseToSnakeCase(String camelCase) { List<String> tokens = new ArrayList<String>(); Matcher matcher = pattern.matcher(camelCase); String acronym = ""; while (matcher.find()) { String found = matcher.group(); if (found.matches("^[A-Z]$")) { acronym += found;//from w w w. j a v a 2 s. c o m } else { if (acronym.length() > 0) { // we have an acronym to add before we continue tokens.add(acronym); acronym = ""; } tokens.add(found.toLowerCase()); } } if (acronym.length() > 0) { tokens.add(acronym); } if (tokens.size() > 0) { StringBuilder sb = new StringBuilder(tokens.remove(0)); for (String s : tokens) { sb.append("_").append(s); } return sb.toString(); } else { return camelCase; } }
From source file:com.romeikat.datamessie.core.base.ui.component.DocumentsFilter.java
private static List<Long> extractDocumentIds(final String text) { final List<Long> documentIds = new LinkedList<Long>(); if (text != null) { final Pattern p = Pattern.compile("\\d+"); final Matcher m = p.matcher(text); while (m.find()) { final String document = m.group(); final long documentId = Long.parseLong(document); documentIds.add(documentId); }/* www . j a va 2 s . co m*/ } return documentIds; }
From source file:com.mgmtp.perfload.agent.Agent.java
static int retrievePid() { try {//from www .j a v a2s . c om // There is no SecurityManager involved retrieving this bean, // but just to be safe, we catch exceptions. String jvmName = ManagementFactory.getRuntimeMXBean().getName(); Matcher matcher = Pattern.compile("\\d*").matcher(jvmName); return matcher.find() ? Integer.parseInt(matcher.group()) : -1; } catch (Exception ex) { System.err.println("Error retrieving process id."); ex.printStackTrace(); return -1; } }
From source file:org.opencastproject.remotetest.server.resource.CaptureResources.java
public static String captureId(HttpResponse response) throws Exception { String pattern = "Unscheduled-\\d+"; Matcher matcher = Pattern.compile(pattern).matcher(EntityUtils.toString(response.getEntity(), "UTF-8")); matcher.find();//from w ww . j a v a2 s . c om return matcher.group(); }
From source file:com.titankingdoms.dev.titanchat.format.Censor.java
/** * Filters the text for phrases and censors the phrases with the censor * /*ww w . j a va2 s. co m*/ * @param text The text to filter * * @param phrases The phrases to censor * * @param censor The censor to use * * @return The filtered text */ public static String filter(String text, List<String> phrases, String censor) { if (text == null) return ""; if (phrases == null) return text; if (censor == null) censor = ""; StringBuffer filtered = new StringBuffer(); String regex = "(" + StringUtils.join(phrases.toArray(new String[0])) + ")"; Pattern phrasePattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher match = phrasePattern.matcher(text); while (match.find()) match.appendReplacement(filtered, Pattern.compile(".").matcher(match.group()).replaceAll(censor)); return match.appendTail(filtered).toString(); }
From source file:com.ufukuzun.myth.dialect.util.ExpressionUtils.java
public static List<String> splitIdFragments(String value) { List<String> idFragments = new ArrayList<String>(); if (StringUtils.isNotBlank(value)) { value = StringUtils.remove(value, "${}"); Matcher matcher = DOLLAR_EXPRESSION_PATTERN.matcher(value); while (matcher.find()) { idFragments.add(matcher.group()); value = StringUtils.remove(value, matcher.group()); }//from w ww . j a v a 2 s . co m idFragments.addAll(Arrays.asList(StringUtils.split(value))); } return idFragments; }
From source file:com.ufukuzun.myth.dialect.util.ExpressionUtils.java
public static List<String> extractRenderExpressions(String value) { List<String> renderExpressions = new ArrayList<String>(); if (StringUtils.isNotBlank(value)) { Matcher matcher = RENDER_EXPRESSION_PATTERN.matcher(value); while (matcher.find()) { renderExpressions.add(matcher.group()); }// www . j a v a2s . co m } return renderExpressions; }