String replacement
@param {String} data
@param {String} result
@param {{regex: RegExp, start: String, end: String}} matches
@returns {String|Boolean}
965006
function write(data, result, matches) {
    if (data.match(matches.regex)) {
        return data.replace(matches.regex, function () {
            return matches.start + "\n\n```\n" + result + "```\n\n" + matches.end;
        });
    }
    return false;
}
1286154
public static String replaceAll(String str, String match, String replacement) {
        String newStr = str;
        int i = newStr.indexOf(match);
        while (i >= 0) {
            newStr = newStr.substring(0, i) + replacement
                    + newStr.substring(i + match.length());
            i = newStr.indexOf(match);
        }
        return newStr;
    }
1318915
function normalize(result) {
  return {
    relevance: result.relevance || 0,
    language: result.language || null,
    value: result.value || []
  }
}
1144496
public boolean match(String str, String regex) {
		if (str == null || regex == null)
			return false;
		if (regex.trim().isEmpty())
			return true;
		return Pattern.compile(regex.trim()).matcher(str).find();
	}
647894
function match(str, patterns) {
    var matched = false;
    if (!_.is(patterns, 'Array')) {
      patterns = [patterns];
    }
    patterns.every(function(pattern) {
      if (!pattern) {
        return true;
      }
      matched = matched || str.search(normalize(pattern)) > -1;
      return !matched;
    });
    return matched;
  }
146070
function matches(regex) {
	return function(val) {
		regex.lastIndex = 0;
		return isString(val) && regex.test(val);
	};
}
1104942
function replaceComplete(text, re, fnc) {
    var doNext = true,
      reg = new RegExp(re); // safe (not literal)
    function fncWrap() {
      doNext = true;
      return fnc.apply(null, arguments);
    }
    // This is faster than using RegExp#exec() and RegExp#lastIndex,
    // because replace() isn't called more than twice in almost all cases.
    while (doNext) {
      doNext = false;
      text = text.replace(reg, fncWrap);
    }
    return text;
  }
716137
function (data) {
    return this.fields.reduce(function (output, field) {
      var replacement = ''
      var placeholder = field.placeholder
      var width = field.width

      if (field.prefix) {
        output += field.prefix
      }
      if (placeholder) {
        replacement = data[placeholder] || ''
        if (width && (placeholder === 'hash' || placeholder === 'chunkhash')) {
          replacement = replacement.slice(0, width)
        }
        output += replacement
      }

      return output
    }, '')
  }
807574
private String stringReplace(String text, String target, String replacement) {
		return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(
				text).replaceAll(replacement);
	}
1055656
function (data) {
    var str = '', start = true;
    var jsondata = '';
    for (var key in data) {
      if (typeof (jsondata = JSON.stringify(data[key])) === 'string') {
        str += (start? '': '&');
        str += encodeURIComponent(key) + '=' + encodeURIComponent(jsondata);
        if (start) { start = false; }
      }
    }
    return str;
  }
1286468
protected static boolean addMatchResult(int limit,
                                            List results,
                                            String pattern,
                                            Object value,
                                            int[] positions,
                                            int len)
    {
        int size = results.size();
        if (size < limit) {
            if (positions == null || len == 0) {
                positions = NO_POSITIONS;
            }
            else {
                int[] original = positions;
                positions = new int[len];
                for (int i=0; i<len; i++) {
                    positions[i] = original[i];
                }
            }
            results.add(new Result(pattern, value, positions));
            return size + 1 < limit;
        }
        else {
            return false;
        }
    }
952130
function(regex, text){
    var nextIndex = 0;
    var result = [];

    var execResult;
    while ((execResult = regex.exec(text))!== null) {
        result.push({
            start: execResult.index, 
            matchLength: execResult[0].length});
    }

    return {
        next: function(){
            return nextIndex < result.length ?
                result[nextIndex++] :
                null;
        }
    };
}
486651
function substitute(originalString, params) {
	"use strict";

	var result = originalString;
	if (params) {
		Object.keys(params).forEach(function(key) {
			result = result.replace(new RegExp('{' + key + '}', 'g'), params[key]);
		});
	}
	return result;
}
139815
function replace(haystack, needle) {
			const replacement = options.resolve ? notate(data, needle.trim()) : data[needle.trim()];

			return VALID_RESULT_TYPES.includes(typeof replacement) ? replacement : options.clean ? '' : haystack;
		}
958266
function(str, match) {
            var replacement;

            // Loop through all subs. Example: ${a.b.c}
            // 0 -> replacement = context[a];
            // 1 -> replacement = context[a][b];
            // 2 -> replacement = context[a][b][c];
            var subs = match.split(/\.+/);
            for (var i=0; i< subs.length; i++) {
                if (i == 0) {
                    replacement = context;
                }
                if (replacement === undefined) {
                    break;
                }
                replacement = replacement[subs[i]];
            }

            if(typeof replacement == "function") {
                replacement = args ?
                    replacement.apply(null, args) :
                    replacement();
            }

            // If replacement is undefined, return the string 'undefined'.
            // This is a workaround for a bugs in browsers not properly 
            // dealing with non-participating groups in regular expressions:
            // http://blog.stevenlevithan.com/archives/npcg-javascript
            if (typeof replacement == 'undefined') {
                return 'undefined';
            } else {
                return replacement; 
            }
        }
323290
function parseSearchResults (html) {
  const $ = cheerio.load(html)
  return $('a')
    .filter(function (index, element) {
      const spans = $(element).find('span')
      return spans.length === 2 && spans.eq(0).text().trim() === 'English'
    })
    .map(function (index, element) {
      const title = $(element).find('span').eq(1).text().trim()
      const url = $(element).attr('href')
      return new SearchResult({
        title: title,
        url: url
      })
    })
    .get()
}
417605
function _replace (regex, replacement, file) {
  const stats = fs.lstatSync(file)
  if (stats.isSymbolicLink()) {
    return
  }
  if (stats.isFile()) {
    let text = fs.readFileSync(file, 'utf-8')
    const ok = typeof regex === 'string' ? text.includes(regex) : regex.test(text)

    if (ok) {
      text = text.replace(regex, replacement)
      console.log(`updating ${relative(file)}`)
      fs.writeFileSync(file, text, 'utf8')
    }
  } else {
    console.log(`${relative(file)} is not a file.`)
  }
}