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:no.dusken.momus.service.drive.GoogleDocsTextConverter.java

/**
 * In case someone likes to have much space between their paragraphs..
 *//*from   ww w  . ja v  a2s .c o  m*/
private String removeEmptyPTags(String in) {
    Matcher m = emptyP.matcher(in);
    return m.replaceAll("");
}

From source file:com.cyberway.issue.io.warc.WARCRecord.java

@Override
protected String getMimetype4Cdx(ArchiveRecordHeader h) {
    final String m = super.getMimetype4Cdx(h);
    // Mimetypes can have spaces in WARCs.  Emitting for CDX, just
    // squash them for now.  Later, quote them since squashing spaces won't
    // work for params that have quoted-string values.
    Matcher matcher = WHITESPACE.matcher(m);
    return matcher.replaceAll("");
}

From source file:com.headstrong.npi.raas.Utils.java

public static String escapeSpecialCharacters(String result) {

    Pattern newLinePattern = Pattern.compile("\\r\\n|\\r|\\n");
    Matcher newLineMatcher = newLinePattern.matcher(result);
    result = newLineMatcher.replaceAll("<br>");
    Pattern singleQuotePattern = Pattern.compile("'");
    Matcher singleQuoteMatcher = singleQuotePattern.matcher(result);
    result = singleQuoteMatcher.replaceAll("");
    return result;

}

From source file:fastacreator.ParseCLI.java

/**
 * Rutger Ozinga. ParseCLI Parses the commandline input and is able to
 * return the wanted option and value./*from   ww w.  j av a  2s  .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("n", true, "Expects a path to place the new tab separated transcript file at.");
    cliOpt.addOption("i", true, "The index of the sequence");
    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 < 2) {
            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)) {
                    setCDSPath(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 newFileString = cliParser.getOptionValue("n");
                Matcher match2 = re.matcher(newFileString);
                String editedTranscriptFileString = match2.replaceAll("");
                Path newFilePath = Paths.get(editedTranscriptFileString);
                if (Files.exists(newFilePath)) {
                    setNewFilePath(newFileString);
                } else {
                    System.out.println("The entered Path does" + " not exits");
                    helpForm.printHelp("Please enter -nt followed by a valid" + " path ", cliOpt);
                    System.exit(0);
                }
                String indexString = cliParser.getOptionValue("i");
                int index = Integer.parseInt(indexString);
                setIndex(index);
            }
        }
    }
}

From source file:org.carrot2.webapp.filter.QueryWordHighlighter.java

private void highlightQueryTerms(Document document, String fieldName, Pattern queryPattern) {
    String field = (String) document.getField(fieldName);

    if (StringUtils.isBlank(field)) {
        return;/*ww w .  java2s.c o m*/
    }

    if (field.length() > maxContentLength) {
        field = field.substring(0, maxContentLength) + "...";
    }

    field = escapeLtGt(field);
    if (queryPattern != null) {
        Matcher matcher = queryPattern.matcher(field);
        field = matcher.replaceAll("<b>$0</b>");
    }

    document.setField(fieldName + HIGHLIGHTED_FIELD_NAME_SUFFIX, field);
}

From source file:no.dusken.momus.service.drive.GoogleDocsTextConverter.java

/**
 * Removes images and tables, should possibly remove more stuff
 * but try to keep the contents, not just the formatting.
 *///from  ww  w . j a  v a2 s.  c o m
private String removeInvalidContent(String in) {
    Matcher m = table.matcher(in);
    String out = m.replaceAll("");

    m = img.matcher(out);
    out = m.replaceAll(" ");

    return out;
}

From source file:de.hybris.platform.order.strategies.paymentinfo.impl.DefaultCreditCardNumberHelper.java

@Override
public String maskCreditCardNumber(final String creditCardNumber) {
    final String _creditCardNumber = normalizeCreditCardNumber(creditCardNumber);

    if (hasValidLength(_creditCardNumber)) {
        final int len = _creditCardNumber.length();

        final Pattern pattern = getOrCreateCachedCardPattern(NUMERIC_PATTERN);
        final Matcher matcher = pattern.matcher(_creditCardNumber.substring(0, len - 4));

        final String _cn = matcher.replaceAll("*");
        return _cn + _creditCardNumber.substring(len - 4, len);
    } else {// www  .  j  a va  2 s .  c o m
        if (LOG.isDebugEnabled()) {
            LOG.debug("Invalid length of the submitted credit card number!");
        }
        return null;
    }
}

From source file:name.milesparker.gerrit.analysis.SimpleFileConverter.java

protected String convertLine(String line) {
    String result = line;// w w w.  ja  va2 s  .  co m
    for (int i = 0; i < patterns.length; i++) {
        if (!replacements[i].fileScope) {
            Matcher matcher = patterns[i].matcher(result);
            result = matcher.replaceAll(replacements[i].replace);
        }
    }
    return result;
}

From source file:name.milesparker.gerrit.analysis.SimpleFileConverter.java

protected String convertFile(String contents) {
    String result = contents;//www . j  av a 2s .  c  o  m
    for (int i = 0; i < patterns.length; i++) {
        if (replacements[i].fileScope) {
            Matcher matcher = patterns[i].matcher(result);
            result = matcher.replaceAll(replacements[i].replace);
        }
    }
    return result;
}

From source file:ar.com.zauber.commons.web.proxy.impl.RegexURLRequestMapper.java

/** @see URLRequestMapper#getProxiedURLFromRequest(HttpServletRequest) */
public final URLResult getProxiedURLFromRequest(final HttpServletRequest request) {
    final Matcher m = regex.matcher(getRequestURI(request));
    final URLResult ret;

    if (m.matches()) {
        final String uri = m.replaceAll(replacePattern);
        try {/* ww w  .j  a va 2 s.c o m*/
            if (base == null) {
                ret = new InmutableURLResult(new URL(uri));
            } else {
                final URLResult r = base.getProxiedURLFromRequest(request);
                if (r.hasResult()) {
                    ret = new InmutableURLResult(new URL(r.getURL().toExternalForm() + uri));
                } else {
                    ret = r;
                }
            }
        } catch (final MalformedURLException e) {
            throw new UnhandledException(e);
        }
    } else {
        ret = new InmutableURLResult();
    }

    return ret;
}