Example usage for java.lang String replaceFirst

List of usage examples for java.lang String replaceFirst

Introduction

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

Prototype

public String replaceFirst(String regex, String replacement) 

Source Link

Document

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

Usage

From source file:com.nebel_tv.content.api.ContentWrapper.java

/**
 *
 * @param url/*from www. jav a  2s.c o m*/
 */
public static String getUrlLastSegment(final String url) {
    return url.replaceFirst(".*/([^/?]+).*", "$1");
}

From source file:Main.java

/**
 * Parses properties from a string and returns them in a map.<p>
 * //from   ww  w .j  a v a  2 s. co  m
 * @param text the text containing the properties 
 * @return the map with the parsed properties 
 */
public static Map<String, String> parseProperties(String text) {

    String[] lines = text.split("\n");
    Map<String, String> result = new HashMap<String, String>();
    for (String line : lines) {
        line = line.replaceFirst("^ +", "");
        line = line.replaceAll("\r", "");
        if (line.startsWith("#")) {
            continue;
        }
        int eqPos = line.indexOf('=');
        if (eqPos > 0) {
            String key = line.substring(0, eqPos);
            String value = line.substring(eqPos + 1);
            result.put(key, value);
        }
    }
    return result;
}

From source file:alpine.util.UuidUtil.java

/**
 * Inserts hyphens in a valid 32 character UUID containing no hyphens.
 * @param uuidWithoutHyphens a UUID without separating hyphens
 * @return a UUID (as a String) containing hyphens
 * @since 1.0.0//from  www  .ja v a2 s  .c  o  m
 */
public static String insertHyphens(String uuidWithoutHyphens) {
    return uuidWithoutHyphens.replaceFirst(
            "(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5");
}

From source file:com.cloudera.cdk.morphline.solr.EnvironmentTest.java

private static Version getMinorLuceneVersion(String version) {
    return Version.valueOf(version.replaceFirst("^(\\d)\\.(\\d).*", "LUCENE_$1$2"));
}

From source file:Main.java

/**
 * Replace, paste arguments one after the other into 
 * the base at positions specified by a RegEx string.
 * //from   w  w w .j  a  v  a2  s.  co m
 * @param base The input string.
 * @param regex The pattern for search.
 * @param args The replacements.
 * @return The modified original string.
 */
public static String paste(String base, String regex, String... args) {
    for (String arg : args) {
        base = base.replaceFirst(regex, arg);
    }
    return base;
}

From source file:Main.java

public static String formatBattletagForWebService(String battletag) {
    if (battletag.matches(VALID_BATTLETAG_PATTERN_POUND)) {
        battletag = battletag.replaceFirst("#", "-");
    }//from w  w w . j  a  v a2  s .co  m

    return battletag;
}

From source file:Main.java

public static String getSetAsDelimitedString(Set<?> list, String delimiter) {
    String r = "";

    for (Object o : list)
        r += delimiter + o.toString();//from  ww w.  ja  va2s . co  m

    return r.replaceFirst(delimiter, "");
}

From source file:Main.java

public static String firstUpperCase(String str) {
    if (android.text.TextUtils.isEmpty(str)) {
        return null;
    }/* w  w  w  .  j  av  a  2s. co m*/
    return str.replaceFirst(str.substring(0, 1), str.substring(0, 1).toUpperCase());
}

From source file:Main.java

public static String creatAcacheKey(Object... param) {
    String key = "";
    for (Object o : param) {
        key += "-" + o;
    }// w w w. j  a  v  a  2 s  . c om
    return key.replaceFirst("-", "");
}

From source file:nl.surfnet.coin.teams.util.PHPRegexConverter.java

/**
 * Strips the delimiter chars from the PHP regex
 *
 * @param phpPattern String with regular expression that may contain | as delimiter
 * @return cleaned up regex pattern, can be {@literal null}
 *//* w  ww .  j a va 2 s .  com*/
public static String convertPHPRegexPattern(String phpPattern) {
    if (StringUtils.hasText(phpPattern)) {
        return phpPattern.replaceFirst("^\\|(.*)\\|$", "$1");
    }
    return phpPattern;
}