List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:nl.inl.util.StringUtil.java
/** * Escape the wildcard characters * and ? in a string with a \ * * @param result/*w w w . j av a 2s .c o m*/ * the original string * @return the string with the wildcard characters escaped with a \. */ public static String escapeWildcardCharacters(String result) { // Escape regex-characters Pattern p = Pattern.compile("([\\?\\*])"); Matcher m = p.matcher(result); result = m.replaceAll("\\\\$1"); return result; }
From source file:nl.inl.util.StringUtil.java
/** * Replace adjacent whitespace characters with a single space * * @param s// w w w .j av a2 s . c om * source string * @return the result */ public static String normalizeWhitespace(String s) { Matcher m = PATT_WHITESPACE.matcher(s); return m.replaceAll(" "); }
From source file:nl.inl.util.StringUtil.java
/** * Escape regex special characters//from w w w.j a va 2s . c om * * @param termStr * the string to escape characters in * @return the escaped string */ public static String escapeRegexCharacters(String termStr) { Matcher m = regexCharacters.matcher(termStr); termStr = m.replaceAll("\\\\$1"); return termStr; }
From source file:org.csware.ee.utils.Tools.java
public static String getNumber(String num) { String regEx = "[^0-9]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(num); return m.replaceAll("").trim(); }
From source file:org.apache.hama.bsp.ResourceManager.java
/** * Get the amount of memory requested in MiB * /*from www.j a v a 2s .co m*/ * @param javaOpts java options * @return mesos formated memory argument */ private static long parseMemory(Configuration conf) { String javaOpts = conf.get("bsp.child.java.opts", "-Xmx200m"); Matcher memMatcher = Pattern.compile("^*-Xmx+([0-9]+)([k,m,g]).*").matcher(javaOpts); if (memMatcher.matches()) { long value = Long.parseLong(memMatcher.group(1)); String unit = memMatcher.group(2); if (unit.equals("k")) { value = (long) Math.ceil((float) value / 1024); } else if (unit.equals("g")) { value = value * 1024; } // remove memory request from the child java opts so it may be added // later conf.set("bsp.child.java.opts", memMatcher.replaceAll("")); return value; } else { // default to 200 MiB return 200; } }
From source file:org.dbflute.solr.cbean.SolrQueryBuilder.java
/** * ???????/*from w ww .ja v a2 s.c o m*/ * @param str * @return */ public static List<String> getExcludedPhraseList(String str) { Matcher phrasePartMatcher = BOOLEAN_PHRASE_PART.matcher(str); String exceptPhraseWord = phrasePartMatcher.replaceAll("").trim(); exceptPhraseWord = exceptPhraseWord.replaceAll("\"", ""); exceptPhraseWord = normalizeFreeword(exceptPhraseWord); String[] splitedArray = exceptPhraseWord.split(" "); List<String> excludedPhraseList = new ArrayList<String>(); for (int i = 0; i < splitedArray.length; i++) { excludedPhraseList.add("\"" + splitedArray[i] + "\""); } return excludedPhraseList; }
From source file:com.fiorano.openesb.application.DmiObject.java
public static String correctName(String name) { Matcher matcher = INVALID_INPUT_CHARS_REGEX.matcher(name); if (matcher.find()) return matcher.replaceAll("_"); return name;/*from w w w . ja va2 s . co m*/ }
From source file:org.csware.ee.utils.Tools.java
/** * ?6?//w w w.jav a 2 s.c om * ??? * @param str * @return ?6??? */ public static String getDynamicPassword(String str) { String regEx = "[^0-9]"; // Pattern continuousNumberPattern = Pattern.compile("[0-9\\.]+"); Pattern continuousNumberPattern = Pattern.compile(regEx); Matcher m = continuousNumberPattern.matcher(str); String dynamicPassword = ""; dynamicPassword = m.replaceAll("").trim().toString(); // while(m.find()){ // if(m.group().length() == 6) { // System.out.print(m.group()); // dynamicPassword = m.group(); // } // } return dynamicPassword; }
From source file:org.jsweet.transpiler.util.Util.java
/** * This function will escape special characters within a string to ensure * that the string will not be parsed as a regular expression. This is * helpful with accepting using input that needs to be used in functions * that take a regular expression as an argument (such as * String.replaceAll(), or String.split()). * /*w w w. j a v a 2 s.c o m*/ * @param regex * - argument which we wish to escape. * @return - Resulting string with the following characters escaped: * [](){}+*^?$.\ */ public static String escapeRegex(final String regex) { Matcher match = REGEX_CHARS.matcher(regex); return match.replaceAll("\\\\$1"); }
From source file:configuration.Cluster.java
/** * Tested on Cluster MP2 only to be validated in the others * @param workbox/*from ww w . ja v a 2s . c om*/ * @param pgName * @param pgVersion * @return */ public static boolean getModule(workflow_properties properties, ArrayList<String> tab, String ref) { ref = ref.toLowerCase(); Pattern pat1 = Pattern.compile(ref); Pattern pat2 = Pattern.compile("\\s*[(]\\w[)]"); if (tab.size() > 0) { for (String s : tab) { s = s.toLowerCase(); Matcher mat1 = pat1.matcher(s); Matcher mat2 = pat2.matcher(s); if (mat1.find()) { if (mat2.find()) s = mat2.replaceAll(""); if (s != "") { Util.removeTrailingSpace(s); properties.put("ClusterModuleIs", s); return true; } } } } return false; }