Example usage for com.liferay.portal.kernel.util StringParser escapeRegex

List of usage examples for com.liferay.portal.kernel.util StringParser escapeRegex

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringParser escapeRegex.

Prototype

public static String escapeRegex(String s) 

Source Link

Document

Escapes the special characters in the string so that they will have no special meaning in a regular expression.

Usage

From source file:com.liferay.wiki.processor.BaseWikiPageRenameContentProcessor.java

License:Open Source License

protected String runRegexps(String content, String title, String newTitle) {
    for (Map.Entry<String, String> entry : regexps.entrySet()) {
        String regexp = entry.getKey();
        String replacement = entry.getValue();

        regexp = regexp.replaceAll("@old_title@", Matcher.quoteReplacement(StringParser.escapeRegex(title)));

        replacement = replacement.replaceAll("@new_title@",
                Matcher.quoteReplacement(StringParser.escapeRegex(newTitle)));

        content = runRegexp(content, regexp, replacement);
    }//from   w  w  w.j a  v a2 s  .  c o  m

    return content;
}