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:org.liberty.android.fantastischmemo.downloader.DownloaderUtils.java

public static String getLastPartFromUrl(final String url) {
    String id = url.replaceFirst(".*/([^/?]+).*", "$1");
    //if (id.contains("%3A")) {
    //   String[] parts = id.split("%3A");
    //   id = parts[parts.length - 1];
    //}//w  ww .j  av a2  s  .  co m
    return id;
}

From source file:Main.java

private static Uri getUriFromPath(String path) {
    String absPath = path.replaceFirst("file://", "");
    File file = new File(absPath);

    if (!file.exists()) {
        Log.e(TAG, "File not found: " + file.getAbsolutePath());
        return Uri.EMPTY;
    }//from w w w .  j a  va 2  s .c  om

    return Uri.fromFile(file);
}

From source file:br.edu.ufcg.supervisor.engine.Simulation.java

private static String eliminateReplicatedRecommendations(String rec) {
    String result = "";
    rec = rec.replaceFirst(".", "");
    String[] temp = rec.split("\\.");
    for (int i = 0; i < temp.length; i++) {
        if (!result.contains(temp[i]))
            result = result + ", " + temp[i];
    }//from www  .j  a  va2s  . co m
    return result.replaceFirst(", ", "") + ".";
}

From source file:Main.java

/**
 * Get a banner data in JSON format from a bundle content.
 * A bundle banner looks like below:// w  ww .  jav a 2 s. co  m
 * \/*!count
 *  * {
 *  *   version: "0.2.1.20170104-release",
 *  *   create: "20170207171112",
 *  *   git: "banner--772c915",
 *  *   digest: "c709b7f91867e371b24f54d6aeea232a"
 *  * }
 *  !*\/
 *
 * @param content a bundle content
 * @return
 */
public static String getBundleBanner(String content) {
    final String commentBegin = "/*!";
    final String commentEnd = "!*/";
    final String asteriskRegex = "\\*";
    final String replacement = "";

    int offsetCountBegin = content.indexOf(commentBegin);
    if (offsetCountBegin == -1) {
        return null;
    }
    offsetCountBegin += commentBegin.length();
    int offsetCountEnd = indexLineBreak(content, offsetCountBegin);
    if (offsetCountEnd == -1) {
        return null;
    }
    String countStr = content.substring(offsetCountBegin, offsetCountEnd);
    int count = Integer.parseInt(countStr);

    String commentBody = content.substring(offsetCountEnd + 1, offsetCountEnd + 1 + count);
    int offsetBodyEnd = commentBody.lastIndexOf(commentEnd);
    if (offsetBodyEnd == -1) {
        return null;
    }
    commentBody = commentBody.substring(0, offsetBodyEnd);

    StringBuilder commentBodyBuilder = new StringBuilder();
    String[] items = splitLineBreak(commentBody);

    for (String item : items) {
        commentBodyBuilder.append(item.replaceFirst(asteriskRegex, replacement));
    }

    return commentBodyBuilder.toString();
}

From source file:com.sonarsource.lits.Dump.java

private static String ruleKeyFromFileName(String fileName) {
    return fileName.replaceFirst("-", ":").substring(0, fileName.length() - EXT.length() - 1);
}

From source file:com.atolcd.pentaho.di.gis.io.AbstractFileReader.java

public static String replaceFileExtension(String fileName, String searchExtension,
        String replacementExtension) {
    return fileName.replaceFirst("(?i)(.*)" + searchExtension, "$1" + replacementExtension);
}

From source file:Main.java

public static String replaceLast(final String text, final String regex, final String replacement) {
    if (text == null || regex == null || replacement == null)
        return text;
    return text.replaceFirst("(?s)" + regex + "(?!.*?" + regex + ")", replacement);
}

From source file:Main.java

/**
 * "Flattens" a phone number into a standard format by eliminating all symbols, etc.
 *//*from  w  ww .j av a  2s  . c  om*/
public static String flattenPhone(String formattedPhone) {
    String flattened = PhoneNumberUtils.stripSeparators(formattedPhone);
    flattened = flattened.replaceAll("\\+", "");
    if (flattened.charAt(0) == '1')
        flattened = flattened.replaceFirst("1", "");
    return flattened;
}

From source file:com.kixeye.chassis.support.test.metrics.cloudwatch.MetricsCloudWatchConfigurationTest.java

private static String removePlaceholder(String placeholder) {
    return placeholder.replaceFirst("\\$", "").replaceFirst("\\{", "").replaceFirst("}", "");
}

From source file:Main.java

public static String removeHtml(String htmlStr) {
    if (TextUtils.isEmpty(htmlStr)) {
        return "";
    }/*  w ww.j av a 2s  .  c om*/
    String html = htmlStr;
    html = html.replaceAll("<(.*?)\\>", " ");//Removes all items in brackets
    html = html.replaceAll("<(.*?)\\\n", " ");//Must be undeneath
    html = html.replaceFirst("(.*?)\\>", " ");//Removes any connected item to the last bracket
    html = html.replaceAll("&nbsp;", " ");
    html = html.replaceAll("&amp;", "&");
    html = html.replaceAll("&lt;", "<");
    html = html.replaceAll("&gt;", ">");
    html = html.replaceAll("&nbsp;", " ");
    return html;
}