List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:de.hybris.platform.order.strategies.paymentinfo.impl.DefaultCreditCardNumberHelper.java
@Override public String normalizeCreditCardNumber(final String creditCardNumber) { if (creditCardNumber == null) { return creditCardNumber; }/*from www.j a va 2s .c o m*/ final Pattern pattern = getOrCreateCachedCardPattern(LEADING_NUMERIC_PATTERN); final Matcher matcher = pattern.matcher(creditCardNumber); return matcher.replaceAll(""); }
From source file:org.j2free.util.HtmlFilter.java
/** * * @param text//from w w w.ja v a 2 s . c o m * @return */ public String strictFilter(String text) { if (text == null || text.equals("")) return text; Pattern p0 = Pattern.compile(HTML_START, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Pattern p1 = Pattern.compile(HTML_END, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher m0 = p0.matcher(text); Matcher m1 = p1.matcher(m0.replaceAll("")); return m1.replaceAll(""); }
From source file:name.vysoky.re.Expression.java
public String apply(String string) { Matcher matcher; String oldString;/*from w ww . j a v a 2s .c o m*/ do { oldString = string; matcher = pattern.matcher(string); string = matcher.replaceAll(replacement); } while (!string.equals(oldString)); return string; }
From source file:org.openpplsoft.sql.StmtLibrary.java
public static OPSStmt convertForJDBCAndGetOPSStmt(final String query, final String[] bindVals, final OPSStmt.EmissionType eType) { final List<String> expandedBindVals = new ArrayList<String>(); final Matcher bindIdxMatcher = bindIdxPattern.matcher(query); while (bindIdxMatcher.find()) { final int bindIdx = Integer.parseInt(bindIdxMatcher.group(1)); // PS bind indices are 1-based, must subtract 1 here. expandedBindVals.add(bindVals[bindIdx - 1]); }//from w w w . j a v a 2s .c o m bindIdxMatcher.reset(); final String newSql = bindIdxMatcher.replaceAll("?"); return new OPSStmt(newSql, expandedBindVals.toArray(new String[expandedBindVals.size()]), eType); }
From source file:mitm.application.djigzo.james.matchers.SubjectTrigger.java
private String removePatternFromSubject(String subject, Matcher matcher, int level) { subject = matcher.replaceAll(""); /*// w w w. jav a 2s . c om * We need to check if the new subject does not contain the pattern again. */ matcher.reset(subject); if (matcher.find()) { if (level < MAX_SUBJECT_RECURSIVE_DEPTH) { /* * Recusively remove pattern */ subject = removePatternFromSubject(subject, matcher, ++level); } else { logger.warn(MAX_SUBJECT_RECURSIVE_DEPTH_REACHED); subject = MAX_SUBJECT_RECURSIVE_DEPTH_REACHED; } } return subject; }
From source file:com.ebay.jetstream.event.processor.esper.EPL.java
/** * Parses a single String containing a semicolon delimited list of EPL statements. * * @param statementBlock/*from w w w . j a va2 s. c o m*/ * the String containing all statements, with each statement separated by a semicolon. */ public void setStatementBlock(String statementBlock) { // TODO: better stmt delimiter parsing (e.g. skip ';' in a string or comment) m_statements.clear(); m_statementsWithComments.clear(); String noncomment = ""; /** * This pattern removes statements with comments. */ if (statementBlock.contains("/*")) { Pattern p = Pattern.compile("/\\*(.*?)\\*/", Pattern.MULTILINE | Pattern.DOTALL); Matcher m = p.matcher(statementBlock); while (m.find()) { noncomment = m.replaceAll(""); } } else { noncomment = statementBlock; } String pattern = "(?s);(?=(?:(?:.*?(?<!\\\\)\"){2})*[^\"]*$)(?=(?:(?:.*?(?<!\\\\)'){2})*[^']*$)"; String[] stmts = noncomment.split(pattern, -1); for (String statement : stmts) { String trimmed = statement.trim(); if (trimmed.length() > 0) { m_statements.add(trimmed); } } }
From source file:org.exoplatform.ecm.webui.utils.Utils.java
public static String getInlineEditingField(Node orgNode, String propertyName) throws Exception { String defaultValue = ""; String idGenerator = ""; Pattern p = Pattern.compile("[^a-zA-Z0-9]"); Matcher m = p.matcher(propertyName); if (orgNode.hasProperty(propertyName)) { defaultValue = orgNode.getProperty(propertyName).getString(); }//from ww w .java2 s . co m idGenerator = m.replaceAll("_"); return getInlineEditingField(orgNode, propertyName, defaultValue, INPUT_TEXT, idGenerator, DEFAULT_CSS_NAME, true); }
From source file:net.sf.j2ep.rules.RewriteRule.java
/** * Will use the pattern and the rewriteTo string to * rewrite the URI before using it to connection to * the end server.//from ww w .ja v a 2 s .c o m * * @see net.sf.j2ep.model.Rule#process(java.lang.String) */ public String process(String uri) { String rewritten = uri; if (isRewriting) { Matcher matcher = matchPattern.matcher(uri); rewritten = matcher.replaceAll(rewriteTo); log.debug("Rewriting URI: " + uri + " >> " + rewritten); } return rewritten; }
From source file:org.eurekastreams.commons.search.explanation.FieldMatchDeterminer.java
/** * Parse the input Explanation string to find which of the input search keywords matched with the input Analyzer. * * @param inExplanationText/* www . j a v a 2 s . c o m*/ * the Explanation text returned from the search * @param searchText * the search string the user typed * @return A Map with the keys representing the fields to analyze and the values as a list of keywords that the user * typed as search parameters that matched the corresponding keyword. */ public FieldMatch determineFieldMatches(final String inExplanationText, final String searchText) { String explanationText = inExplanationText; FieldMatch matchedKeywords = new FieldMatch(); if (fieldsToAnalyze.size() == 0) { return matchedKeywords; } log.debug("Explanation:" + explanationText); // Remove the boost values, makes things easier... Pattern boostPattern = Pattern.compile("\\^[0-9]+.[0-9]+"); Matcher boostPatternMatcher = boostPattern.matcher(explanationText); explanationText = boostPatternMatcher.replaceAll(""); // convert the keywords to the analyzed form, then store them in a hashtable of <tokenizedForm, originalKeyword> Map<String, String> tokenizedKeywords = tokenizeKeywords(searchText); // We now have a Map with the tokenized keyword as the key, the original search word as the value. // Start looking through the explanation for the values for (String fieldName : fieldsToAnalyze) { Pattern weightPattern = Pattern.compile("\\sweight\\(" + fieldName + ":(\\w+)\\s", java.util.regex.Pattern.CASE_INSENSITIVE | java.util.regex.Pattern.MULTILINE); Matcher m = weightPattern.matcher(explanationText); boolean result = m.find(); while (result) { matchedKeywords.addMatch(fieldName, tokenizedKeywords.get(m.group(1))); result = m.find(); } } return matchedKeywords; }
From source file:net.sf.j2ep.rules.RewriteRule.java
/** * @see net.sf.j2ep.model.Rule#revert(java.lang.String) *//*from w w w.j av a 2 s .c om*/ public String revert(String uri) { String rewritten = uri; if (isReverting) { Matcher matcher = revertPattern.matcher(uri); rewritten = matcher.replaceAll(revertTo); log.debug("Reverting URI: " + uri + " >> " + rewritten); } return rewritten; }