Example usage for java.util.regex Matcher replaceAll

List of usage examples for java.util.regex Matcher replaceAll

Introduction

In this page you can find the example usage for java.util.regex Matcher replaceAll.

Prototype

public String replaceAll(Function<MatchResult, String> replacer) 

Source Link

Document

Replaces every subsequence of the input sequence that matches the pattern with the result of applying the given replacer function to the match result of this matcher corresponding to that subsequence.

Usage

From source file:createconversioncdsfile.ParseCLI.java

/**
 * Rutger Ozinga. ParseCLI Parses the commandline input and is able to
 * return the wanted option and value.//from ww w .  j a  v a 2  s.c  o m
 *
 * @param args are commandline arguments.
 * @throws org.apache.commons.cli.ParseException an exception
 */
public ParseCLI(final String[] args) throws org.apache.commons.cli.ParseException {
    HelpFormatter helpForm = new HelpFormatter();
    Options cliOpt = new Options();
    cliOpt.addOption("h", "help", false, "Displays help");
    cliOpt.addOption("p", true, "Expects a path to a protein fasta file.");
    cliOpt.addOption("t", true, "Expects a path to a transcript fasta file.");
    cliOpt.addOption("c", true, "Expects a path to a conversion file at.");
    cliOpt.addOption("cds", true, "Expects a path to a cds file at.");
    cliOpt.addOption("o", true, "Expects a path to place the new tab separated protein file at");
    if (args.length == 0) {
        helpForm.printHelp("Please enter all the " + "options below. ", cliOpt);
        System.exit(0);
    } else {
        BasicParser parser = new BasicParser();
        CommandLine cliParser = parser.parse(cliOpt, args);
        if (cliParser.getOptions().length < 4) {
            System.out.println(
                    "Error : " + "Please enter all options in" + " order for this program to work" + "!\n");
            helpForm.printHelp("Please enter all of the  " + "option ", cliOpt);
            System.exit(0);
        } else {
            if (cliParser.hasOption("h") && cliParser.hasOption("help")) {
                helpForm.printHelp("Command Line Help:\n", cliOpt);
                System.exit(0);
            } else {
                String snpFileString = cliParser.getOptionValue("p");
                Path snpPath = Paths.get(snpFileString);
                if (Files.exists(snpPath)) {
                    setProtPath(snpPath);
                } else {
                    System.out.println("The entered Path does" + " not exits");
                    helpForm.printHelp("Please enter -p followed by a valid" + " path ", cliOpt);
                    System.exit(0);
                }
                String conversionFileString = cliParser.getOptionValue("c");
                Path conversionPath = Paths.get(conversionFileString);
                if (Files.exists(conversionPath)) {
                    setConversionFilePath(conversionPath);
                } else {
                    System.out.println("The entered Path does" + " not exits");
                    helpForm.printHelp("Please enter -c followed by a valid" + " path ", cliOpt);
                    System.exit(0);
                }
                String cdsFileString = cliParser.getOptionValue("cds");
                Path cdsPath = Paths.get(cdsFileString);
                if (Files.exists(cdsPath)) {
                    setCdsPath(cdsPath);
                } else {
                    System.out.println("The entered Path does" + " not exits");
                    helpForm.printHelp("Please enter -cds followed by a valid" + " path ", cliOpt);
                    System.exit(0);
                }
                String transcriptFileString = cliParser.getOptionValue("t");
                Path transcriptPath = Paths.get(transcriptFileString);
                if (Files.exists(transcriptPath)) {
                    setTransPath(transcriptPath);
                } else {
                    System.out.println("The entered Path does" + " not exits");
                    helpForm.printHelp("Please enter -t followed by a valid" + " path ", cliOpt);
                    System.exit(0);
                }
                String newFileString = cliParser.getOptionValue("o");
                Matcher match = re.matcher(newFileString);
                String editedFileString = match.replaceAll("");
                Path newPath = Paths.get(editedFileString);
                if (Files.exists(newPath)) {
                    setNewFilePath(newFileString);
                } else {
                    System.out.println("The entered Path does" + " not exits");
                    helpForm.printHelp("Please enter -o followed by a valid" + " path ", cliOpt);
                    System.exit(0);
                }
            }
        }
    }
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.S2SAdobeFormAttachmentBaseGenerator.java

public String checkAndReplaceInvalidCharacters(String text) {
    String cleanText = text;/*  w  w w . ja  v  a  2  s . c  o m*/
    if (text != null) {
        Pattern pattern = Pattern.compile(REGEX_TITLE_FILENAME_PATTERN);
        Matcher matcher = pattern.matcher(text);
        cleanText = matcher.replaceAll(REPLACEMENT_CHARACTER);
        if (cleanText.length() > 50) {
            cleanText = cleanText.substring(0, 50);
        }
    }
    return cleanText;
}

From source file:org.mili.ant.PropertiesReplacerImpl.java

private String replace(String rep, String data) {
    String what = actuals.what.getContent();
    if (actuals.replace.isRegexp()) {
        rep = rep.replace("$", "\\$");
        Matcher m = Pattern.compile(what, Pattern.MULTILINE).matcher(data);
        if (m.find()) {
            data = m.replaceAll(rep);
        } else if (actuals.replaceFile.isHaltOnError()) {
            throwNothingToReplaceException();
        }//from ww  w .  ja v  a 2s .  c om
    } else {
        int index = data.indexOf(what);
        if (index >= 0) {
            data = data.replace(what, rep);
        } else if (index < 0 && actuals.replaceFile.isHaltOnError()) {
            throwNothingToReplaceException();
        }
    }
    return data;
}

From source file:com.buession.cas.service.persondir.support.jdbc.AbstractJdbcPersonAttributeDao.java

@Override
protected PartialWhereClause appendAttributeToQuery(PartialWhereClause queryBuilder, String dataAttribute,
        List<Object> queryValues) {
    for (final Object queryValue : queryValues) {
        final String queryString = queryValue != null ? queryValue.toString() : null;

        if (StringUtils.isNotBlank(queryString)) {
            if (queryBuilder == null) {
                queryBuilder = new PartialWhereClause();
            } else if (queryBuilder.sql.length() > 0) {
                queryBuilder.sql.append(" ").append(queryType.toString()).append(" ");
            }/*w w w . java 2s  .c  om*/

            // Convert to SQL wildcard
            final Matcher queryValueMatcher = IPersonAttributeDao.WILDCARD_PATTERN.matcher(queryString);
            final String formattedQueryValue = queryValueMatcher.replaceAll("%");

            queryBuilder.arguments.add(formattedQueryValue);

            if (dataAttribute != null) {
                queryBuilder.sql.append(dataAttribute);
                if (formattedQueryValue.equals(queryString)) {
                    queryBuilder.sql.append(" = ");
                } else {
                    queryBuilder.sql.append(" LIKE ");
                }
            }

            queryBuilder.sql.append("?");
        }
    }

    return queryBuilder;
}

From source file:de.escidoc.core.test.aa.StatisticReaderAbstractTest.java

/**
 * triggers preprocessing.//from w w w  .j  av a 2  s.  c  om
 *
 * @param methodIndex methodIndex
 * @throws Exception If anything fails.
 */
private void triggerPreprocessing(final String methodIndex) throws Exception {
    String urlParameters = PREPROCESSING_URL + System.currentTimeMillis();

    Matcher methodIndexMatcher = METHOD_INDEX_PATTERN.matcher(urlParameters);
    urlParameters = methodIndexMatcher.replaceAll(methodIndex);

    String httpUrl = HttpHelper.createUrl(Constants.PROTOCOL, Constants.HOST_PORT,
            Constants.ESCIDOC_BASE_URI + urlParameters);
    long time = System.currentTimeMillis();
    HttpResponse httpRes = HttpHelper.executeHttpRequest(null, Constants.HTTP_METHOD_GET, httpUrl, null, null,
            null);
    String response = EntityUtils.toString(httpRes.getEntity(), HTTP.UTF_8);
    httpRes.getEntity().consumeContent();
    response = " preprocessing needed " + (System.currentTimeMillis() - time) + response;
    try {
        assertMatches("String does not match es expected. " + response,
                "Operation completed successfully without a return value", response);

    } catch (final AssertionError e) {
        if (methodIndex.equals(STATISTIC_PREPROCESSR_METHOD_INDEX)) {
            triggerPreprocessing("1");
        } else {
            throw e;
        }
    }
}

From source file:org.lanes.text.mining.Similarity.java

public ModifiableSolrParams formulateQuery(String query, int rows) {

    ModifiableSolrParams params = new ModifiableSolrParams();

    Matcher replace1 = Pattern.compile("_").matcher(query);
    query = replace1.replaceAll(" ");

    params.set("q", query);
    Matcher matcherunigram = Pattern.compile("^text:([^\\s]+)$").matcher(query);
    if (matcherunigram.find()) {
        String searchterm = matcherunigram.group(1);
        params.set("fl", "*,totaltermfreq(text," + searchterm + ")");
    }//  w w  w.  j ava2 s . c om
    params.set("fq",
            "-titleText:\"(disambiguation)\" " + "-titleText:\"Book:\" " + "-titleText:\"Category:\" "
                    + "-titleText:\"Education Program:\" " + "-titleText:\"File:\" " + "-titleText:\"Image:\" "
                    + "-titleText:\"Help:\" " + "-titleText:\"Media:\" " + "-titleText:\"MediaWiki:\" "
                    + "-titleText:\"Portal:\" " + "-titleText:\"Template:\" " + "-titleText:\"TimedText:\" "
                    + "-titleText:\"User:\" " + "-titleText:\"Similarity:\" " + "-titleText:\"WP:\" "
                    + "-titleText:\"Wikipedia:\" " + "-titleText:\"WT:\"");
    params.set("start", 0);
    params.set("rows", rows);
    //params.set("debugQuery", true);
    //params.set("debug.explain.structured", true);

    return params;
}

From source file:org.lanes.text.mining.Similarity.java

public double getDocCount(String term1, String term2) {

    Matcher replace1 = Pattern.compile("_").matcher(term1);
    term1 = replace1.replaceAll(" ");
    Matcher replace2 = Pattern.compile("_").matcher(term2);
    term2 = replace2.replaceAll(" ");

    double n = 0;
    double f = 0;
    String phrasescombi = "";

    if ((term2.equals("") && !stopwords.containsKey(term1.toLowerCase())) || (!term2.equals("")
            && !stopwords.containsKey(term1.toLowerCase()) && !stopwords.containsKey(term2.toLowerCase()))) {
        try {/*from  w w  w  . j  a  v a2s .c  om*/
            ModifiableSolrParams param = null;
            if (!term2.equals("")) {
                param = formulateQuery("text:\"" + term1 + "\" AND \"" + term2 + "\"", 1);
            } else {
                param = formulateQuery("text:\"" + term1 + "\"", 1);
            }

            Double[] stats = sendQuery(param);
            n = stats[0];
            f = stats[1];

        } catch (Exception e) {
            //System.err.println(e.getMessage());
        }
    }

    return n;
}

From source file:org.eclipse.mylyn.reviews.r4e.upgrade.utils.SimpleFileConverter.java

/**
 * Method convert.//from  w  ww  .  j  a v a 2s .co  m
 * @param aLine - String
 * @return String
 */
private String convert(String aLine) {
    String result = aLine;
    for (int i = 0; i < fPatterns.length; i++) {
        Matcher matcher = fPatterns[i].matcher(result);
        result = matcher.replaceAll(fReplacements[i].getReplace());
    }
    return result;
}

From source file:net.sf.groovyMonkey.actions.PasteScriptFromClipboardAction.java

private List<String> extractScriptsFromText(final TextAndRTF text) {
    final List<String> result = array();
    final Pattern pattern = compile(PUBLISH_BEFORE_MARKER + "\\s*(.*?)\\s*" + PUBLISH_AFTER_MARKER, DOTALL);
    final Pattern crpattern = compile("\r\n?");
    if (text.text != null) {
        final Matcher matcher = pattern.matcher(text.text);
        while (matcher.find()) {
            String string = matcher.group(1);
            final Matcher crmatch = crpattern.matcher(string);
            string = crmatch.replaceAll("\n");
            if (string.indexOf("\n") >= 0)
                result.add(string);//ww w  .ja  v a 2  s.c om
        }
    }
    if (result.isEmpty() && text.rtf != null) {
        final Matcher matcher = pattern.matcher(text.rtf);
        final Pattern escapesPattern = compile("\\\\(.)");
        while (matcher.find()) {
            String string = matcher.group(1);
            string = string.replaceAll("\\\\line", "\n");
            final Matcher escapes = escapesPattern.matcher(string);
            string = escapes.replaceAll("$1");
            final Matcher crmatch = crpattern.matcher(string);
            string = crmatch.replaceAll("\n");
            if (string.indexOf("\n") >= 0)
                result.add(string);
        }
    }
    return result;
}

From source file:com.akamai.edgegrid.signer.EdgeGridV1Signer.java

private String canonicalizeHeaderValue(String headerValue) {
    headerValue = headerValue.trim();/* w w  w.  j a  v a  2s.  c  o  m*/
    if (StringUtils.isNotBlank(headerValue)) {
        Matcher matcher = PATTERN_SPACES.matcher(headerValue);
        headerValue = matcher.replaceAll(" ");
    }
    return headerValue;
}