Java Regex String Replace replace(Matcher m, String rv, Object value)

Here you can find the source of replace(Matcher m, String rv, Object value)

Description

replace

License

Mozilla Public License

Declaration

private static String replace(Matcher m, String rv, Object value) 

Method Source Code

//package com.java2s;
/*/*www  .ja  v a  2 s  . co m*/
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import java.util.regex.Matcher;

public class Main {
    private static String replace(Matcher m, String rv, Object value) {
        while (m.find()) {
            if (m.group(2) != null) {
                rv = rv.replace(m.group(0), String.format(m.group(2), value));
            } else {
                rv = rv.replace(m.group(0), String.valueOf(value));
            }
        }
        return rv;
    }
}

Related

  1. replace$(String text, Map vars)
  2. replace(CharSequence target, CharSequence replacement, String string)
  3. replace(final String regex, final String replacement, final StringBuffer source, boolean all)
  4. replace(final String template, final Map map, final String prefix, final String suffix, boolean useMapForMatching)
  5. replace(Pattern pattern, String src, Function handler)
  6. replace(String content, String name, String value)
  7. replace(String input, Pattern pattern, Function replacementGenerator)
  8. replace(String input, Pattern regex, Function converter)