Example usage for org.apache.commons.lang3 RegExUtils replaceAll

List of usage examples for org.apache.commons.lang3 RegExUtils replaceAll

Introduction

In this page you can find the example usage for org.apache.commons.lang3 RegExUtils replaceAll.

Prototype

public static String replaceAll(final String text, final String regex, final String replacement) 

Source Link

Document

Replaces each substring of the text String that matches the given regular expression with the given replacement.

This method is a null safe equivalent to:
  • text.replaceAll(regex, replacement)
  • Pattern.compile(regex).matcher(text).replaceAll(replacement)

A null reference passed to this method is a no-op.

Unlike in the #replacePattern(String,String,String) method, the Pattern#DOTALL option is NOT automatically added.

Usage

From source file:de.jfachwert.bank.BLZ.java

/**
 * Eine BLZ darf maximal 8-stellig sein.
 *
 * @param blz die Bankleitzahl//from ww w  .j a  va 2  s.co  m
 * @return die Bankleitzahl zur Weitervarabeitung
 */
public static String validate(String blz) {
    String normalized = RegExUtils.replaceAll(blz, "\\s", "");
    return NUMBER_VALIDATOR.validate(normalized);
}

From source file:de.jfachwert.net.Telefonnummer.java

/**
 * Liefert die Nummer der Ortsvermittlungsstelle, d.h. die Telefonnummer
 * ohne Vorwahl und Laenderkennzahl./*from  w w  w .j av  a  2  s .c  o  m*/
 *
 * @return z.B. "32168"
 */
public Telefonnummer getRufnummer() {
    String inlandsnummer = RegExUtils.replaceAll(this.getInlandsnummer().toString(), "[ /]+", " ");
    return new Telefonnummer(StringUtils.substringAfter(inlandsnummer, " ").replaceAll(" ", ""));
}

From source file:com.netflix.genie.web.jobs.workflow.impl.InitialSetupTask.java

/**
 * Helper to convert a set of tags into a string that is a suitable value for a shell environment variable.
 * Adds double quotes as necessary (i.e. in case of spaces, newlines), performs escaping of in-tag quotes.
 * Input tags are sorted to produce a deterministic output value.
 *
 * @param tags a set of tags or null//  w  w  w.ja  v  a2  s  .  co  m
 * @return a CSV string
 */
@VisibleForTesting
String tagsToString(final Set<String> tags) {
    final ArrayList<String> sortedTags = new ArrayList<>(tags == null ? Collections.emptySet() : tags);
    // Sort tags for the sake of determinism (e.g., tests)
    sortedTags.sort(Comparator.naturalOrder());
    final String joinedString = StringUtils.join(sortedTags, ',');
    // Escape quotes
    return RegExUtils.replaceAll(RegExUtils.replaceAll(joinedString, "\'", "\\\'"), "\"", "\\\"");
}

From source file:com.erudika.scoold.utils.ScooldUtils.java

public String getSpaceName(String space) {
    return RegExUtils.replaceAll(space, "^scooldspace:[^:]+:", "");
}

From source file:com.netflix.genie.web.services.impl.JobSpecificationServiceImpl.java

/**
 * Helper to convert a set of tags into a string that is a suitable value for a shell environment variable.
 * Adds double quotes as necessary (i.e. in case of spaces, newlines), performs escaping of in-tag quotes.
 * Input tags are sorted to produce a deterministic output value.
 *
 * @param tags a set of tags or null//from   w  ww  .j ava  2  s .com
 * @return a CSV string
 */
private String tagsToString(final Set<String> tags) {
    final List<String> sortedTags = Lists.newArrayList(tags);
    // Sort tags for the sake of determinism (e.g., tests)
    sortedTags.sort(Comparator.naturalOrder());
    final String joinedString = StringUtils.join(sortedTags, ',');
    // Escape quotes
    return RegExUtils.replaceAll(RegExUtils.replaceAll(joinedString, "\'", "\\\'"), "\"", "\\\"");
}