Example usage for java.lang String replaceAll

List of usage examples for java.lang String replaceAll

Introduction

In this page you can find the example usage for java.lang String replaceAll.

Prototype

public String replaceAll(String regex, String replacement) 

Source Link

Document

Replaces each substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:Main.java

public static String decryptMessageReceived(String content) {
    if (content == null) {
        return null;
    }//  w  w  w  .  j  a  v  a2s  .  com
    content = content.replaceAll("&dq", "\"");
    content = content.replaceAll("&bs", "\\\\");
    content = content.replaceAll("&nl", "\n");
    return content;
}

From source file:Main.java

/**
 * Trim all non-numeric characters off of the string
 * //  w w w  .  ja  va  2  s  .  c  o  m
 * @param value
 * @return
 */
public static String trimNonNumericCharacters(String value) {
    //keep only numeric characters
    if (value != null)
        value = value.replaceAll("[^0-9]", "");
    return value;
}

From source file:Main.java

public static String cleanInvalidXmlChars(String text) {
    String re = "[^^\u0009\r\n\u0020-\uD7FF\uE000-\uFFFD]";
    return text.replaceAll(re, " ");
}

From source file:Main.java

/**
 * encode the string because of the xml convertion.
 *
 * @param str/*from   w w  w  . ja  v a2  s. com*/
 * @return
 */
public static String encodeStringForXml(String str) {
    if (str == null)
        return str;
    str = str.replaceAll("\"", """);
    str = str.replaceAll("<", "&lt;");
    str = str.replaceAll(">", "&gt;");
    str = str.replaceAll("&", "&amp;");
    return str;
}

From source file:Main.java

public static String dealXmlContent(String xmlContent) {
    String result = "";
    if (xmlContent != null) {
        result = xmlContent.replaceAll("&", "&amp;");
        result = result.replaceAll("<", "&lt;");
        result = result.replaceAll(">", "&gt;");
    }/*w  ww . j a v  a2s.c  o  m*/
    return result;
}

From source file:Main.java

/**
 * Calculates a key name from a file name.
 * @param friendlyName/*  w  ww  .j a v  a2s.  co  m*/
 * @return a file system friendly name for this password key
 */
public static String calculateKey(String friendlyName) {
    friendlyName = friendlyName.trim().toLowerCase();
    friendlyName = friendlyName.replaceAll("\\Q \\E", "-");
    friendlyName = friendlyName.replaceAll("[!@#$%^&*()+\"]", "_");
    return friendlyName;
}

From source file:com.flysystem.core.util.PathUtil.java

/**
 * Normalize path./*from w w w .  j a  v  a 2 s  .  c  o  m*/
 *
 * @return string
 */
public static String normalizePath(String path) {
    path = path.replaceAll("^[^[/\\\\]]*[/\\\\]", ""); //replace all / and \ at the start of the string
    return FilenameUtils.normalizeNoEndSeparator(path);
}

From source file:Main.java

/**
 * Validates and processes the given Url
 * @param    url The given Url to process
 * @return   Pre-process Url as string */
public static String cleanUrl(StringBuilder url) {
    //ensure that the urls are absolute
    Pattern pattern = Pattern.compile("^(https?://[^/]+)");
    Matcher matcher = pattern.matcher(url);
    if (!matcher.find())
        throw new IllegalArgumentException("Invalid Url format.");

    //get the http protocol match
    String protocol = matcher.group(1);

    //remove redundant forward slashes
    String query = url.substring(protocol.length());
    query = query.replaceAll("//+", "/");

    //return process url
    return protocol.concat(query);
}

From source file:Main.java

public static String escapeUnformChar(String str, String c) {
    if (str == null || str.length() == 0)
        return str;
    return str.replaceAll("[\u0000-\u0008\u000b\u000c\u000e-\u001f]", c);
}

From source file:jp.co.opentone.bsol.framework.core.util.ConvertUtil.java

/**
 * ??????./* w ww.j a  v a  2 s  .c o  m*/
 * {@link String#replaceAll(String, String)}?2?
 * ???????????????.
 * @param s 
 * @return ?
 */
public static String escapeBackReference(String s) {
    String result = s;
    result = result.replaceAll("\\\\", "\\\\\\\\");
    result = result.replaceAll("\\$", "\\\\\\$");
    return result;
}