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:Correct.java

public static void execute(String One, String Two) {

    Two = Two.replaceAll("\\\\n", "\n");
    try {/*from  w w  w .  j a va  2s .  co  m*/
        System.out.println("Regex = " + One);
        System.out.println("Input = " + Two);

        Pattern pattern = Pattern.compile(One);
        Matcher match = pattern.matcher(Two);

        while (match.find()) {
            System.out.println("Found [" + match.group() + "]\nStarting at " + match.start() + " , \nEnding at "
                    + (match.end() - 1));
        }
    } catch (PatternSyntaxException pse) {

        System.err.println("Bad regex: " + pse.getMessage());
        System.err.println("Description: " + pse.getDescription());
        System.err.println("Index: " + pse.getIndex());
        System.err.println("Incorrect pattern: " + pse.getPattern());
    }
}

From source file:Main.java

/**
 * Removes the "<" and "</" from the beginning and end of a tag
 * //from   w w w.  ja  v  a2 s.  c  om
 * @param tag
 *            The tag text to strip
 * @return A string with the item removed
 */
public static String stripTagEndings(String tag) {
    String tempName = tag.replaceAll("</", ""); //$NON-NLS-1$ //$NON-NLS-2$
    tempName = tempName.replaceAll(">", ""); //$NON-NLS-1$ //$NON-NLS-2$
    return tempName.replaceAll("<", ""); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:Main.java

/**
 * This function decodes a base 2 string into its corresponding byte array.
 *
 * @param base2 The base 2 encoded string.
 * @return The corresponding byte array.
 *///  www  . j  av  a 2  s.  c  o  m
static public byte[] decode(String base2) {
    String string = base2.replaceAll("\\s", ""); // remove all white space
    int length = string.length();
    byte[] bytes = new byte[(int) Math.ceil(length / 8)];
    for (int i = 0; i < bytes.length; i++) {
        int b = 0;
        for (int j = 0; j < 8; j++) {
            char character = string.charAt(i * 8 + j);
            int bit = lookupTable.indexOf(character);
            if (bit < 0)
                throw new NumberFormatException("Attempted to decode a string that is not base 2: " + string);
            b = (b << 1) | bit;
        }
        bytes[i] = (byte) b;
    }
    return bytes;
}

From source file:Main.java

public static String xmlEscape(String str) {
    for (String[] escapee : escapees) {
        str = str.replaceAll(escapee[0], escapee[1]);
    }/*from   w  ww . ja  va  2s . co  m*/
    return str;
}

From source file:Main.java

public static String decodeXML(String XML) {

    String result = XML.replaceAll(LT_A, LT);
    result = result.replaceAll(GT_A, GT);
    result = result.replaceAll(QUOTE_A, QUOTE);
    result = result.replaceAll(APOS_A, APOS);
    result = result.replaceAll(AND_A, AND);
    result = result.replaceAll(NBSP_A, SPACE);

    /*// w  w w.  ja  va2s.  c o  m
     * if(result.contains("amp;")){ log.severe("decodeXML Orig XML = "+XML);
     * log.severe("decodeXML Final XML = "+result); }
     */

    /*
     * if(result.contains("&")){
     * log.severe("decodeXML Final XML contains amp = "+result); }
     */
    return result;
}

From source file:com.rhc.dynamic.pipeline.utils.TestUtils.java

public static String removeWhiteSpace(String input) {
    return input.replaceAll("\\s+", "");
}

From source file:Main.java

/**
 * XML attribute value Encode/*from  w  ww .j  a  v a  2s  . c om*/
 * @param s xml attribute values
 * @return convert "&"->"&amp;", "<"->"&lt;", ">"->"&gt;" 
 */
public static String encodeXMLReservedWords(String s) {
    if (s.contains("&")) {
        s = s.replaceAll("&", "&amp;");
    }

    if (s.contains("<")) {
        s = s.replaceAll("<", "&lt;");
    }

    if (s.contains(">")) {
        s = s.replaceAll(">", "&gt;");
    }
    return s;
}

From source file:Main.java

public static String getNoTagsTrimText(String xml) {
    Matcher m = tagPattern.matcher(xml);
    if (!m.find()) {
        return xml;
    }//  w  ww .  j  a  v  a2s  .  co m
    String replaced = m.replaceAll("");

    replaced = replaced.replaceAll("\\r\\n", "");
    replaced = replaced.replaceAll("\\n", "");
    replaced = replaced.replaceAll("\\t", "");

    replaced = replaced.replaceAll("\\s+", " ");
    replaced = replaced.trim();

    return replaced;
}

From source file:br.edimarmanica.weir2.rule.Loader.java

public static String formatURL(String url) {
    return url.replaceAll(".*/", "").replaceAll("\\..*", "");
}

From source file:net.jingx.main.Main.java

private static String generateSecret(String key) {
    String s = key;
    s = s.replaceAll(" ", "");
    s = s.replaceAll("1", "I");
    s = s.replaceAll("0", "O");
    return s;// www. j  av a2 s .  com
}