Replaces all occurrences of the regular expression in the value with the replacement value.
@param regEx regular expression to match.
@param value value to replace in.
@param replace replacement pattern.
@return result.
555076
public String replaceAllInWith(String regEx, String value, String replace) {
        String result = null;
        if (value != null) {
            if (replace == null) {
                // empty cell in table is sent as null
                replace = "";
            }
            result = getMatcher(regEx, value).replaceAll(replace);
        }
        return result;
    }
659249
public Map<String, String> getValByRegex(String regex) {
    Pattern p = Pattern.compile(regex);

    Map<String, String> result = new HashMap<String, String>();
    Matcher m;

    for (Map.Entry<Object, Object> item: getProps().entrySet()) {
      if (item.getKey() instanceof String &&
            item.getValue() instanceof String) {
        m = p.matcher((String) item.getKey());
        if (m.find()) { // match
          result.put((String) item.getKey(), (String) item.getValue());
        }
      }
    }
    return result;
  }
537771
public function regexplace($pattern, $replacement)
    {
        $result = preg_replace($pattern, $replacement, $this->getInternalValue());
        $this->setInternalValue($result);

        return $this;
    }
478869
public static String regexpReplace(String str, String regex, String replacement) {
		if (regex.isEmpty()) {
			return str;
		}
		try {
			// we should use StringBuffer here because Matcher only accept it
			StringBuffer sb = new StringBuffer();
			Matcher m = REGEXP_PATTERN_CACHE.get(regex).matcher(str);
			while (m.find()) {
				m.appendReplacement(sb, replacement);
			}
			m.appendTail(sb);
			return sb.toString();
		} catch (Exception e) {
			LOG.error(
				String.format("Exception in regexpReplace('%s', '%s', '%s')", str, regex, replacement),
				e);
			// return null if exception in regex replace
			return null;
		}
	}
1069057
public List<RuleMatchApplication> applySuggestionsToOriginalText(RuleMatch match) {
    List<String> replacements = new ArrayList<>(match.getSuggestedReplacements());
    boolean hasRealReplacements = replacements.size() > 0;
    if (!hasRealReplacements) {
      // create a pseudo replacement with the error text itself
      String plainText = textMapping.getPlainText();
      replacements.add(plainText.substring(match.getFromPos(), match.getToPos()));
    }

    List<RuleMatchApplication> ruleMatchApplications = new ArrayList<>();
    Location fromPosLocation = textMapping.getOriginalTextPositionFor(match.getFromPos() + 1);  // not zero-based!
    Location toPosLocation = textMapping.getOriginalTextPositionFor(match.getToPos() + 1);

    /*System.out.println("=========");
    System.out.println(textMapping.getMapping());
    System.out.println("=========");
    System.out.println(textMapping.getPlainText());
    System.out.println("=========");
    System.out.println(originalText);
    System.out.println("=========");*/

    int fromPos = LocationHelper.absolutePositionFor(fromPosLocation, originalText);
    int toPos = LocationHelper.absolutePositionFor(toPosLocation, originalText);
    for (String replacement : replacements) {
      String errorText = textMapping.getPlainText().substring(match.getFromPos(), match.getToPos());
      // the algorithm is off a bit sometimes due to the complex syntax, so consider the next whitespace:
      int contextFrom = findNextWhitespaceToTheLeft(originalText, fromPos);
      int contextTo = findNextWhitespaceToTheRight(originalText, toPos);

      /*System.out.println(match + ":");
      System.out.println("match.getFrom/ToPos(): " + match.getFromPos() + "/" + match.getToPos());
      System.out.println("from/toPosLocation: " + fromPosLocation + "/" + toPosLocation);
      System.out.println("from/toPos: " + fromPos + "/" + toPos);
      System.out.println("contextFrom/To: " + contextFrom + "/" + contextTo);*/

      String context = originalText.substring(contextFrom, contextTo);
      String text = originalText.substring(0, contextFrom)
              + errorMarker.getStartMarker()
              + context
              + errorMarker.getEndMarker()
              + originalText.substring(contextTo);
      String newContext;
      if (StringUtils.countMatches(context, errorText) == 1) {
        newContext = context.replace(errorText, replacement);
      } else {
        // This may happen especially for very short strings. As this is an
        // error, we don't claim to have real replacements:
        newContext = context;
        hasRealReplacements = false;
      }
      String newText = originalText.substring(0, contextFrom)
              // we do a simple string replacement as that works even if our mapping is off a bit:
              + errorMarker.getStartMarker()
              + newContext
              + errorMarker.getEndMarker()
              + originalText.substring(contextTo);
      RuleMatchApplication application;
      if (hasRealReplacements) {
        application = RuleMatchApplication.forMatchWithReplacement(match, text, newText, errorMarker);
      } else {
        application = RuleMatchApplication.forMatchWithoutReplacement(match, text, newText, errorMarker);
      }
      ruleMatchApplications.add(application);
    }
    return ruleMatchApplications;
  }
1065145
public static String replace(String str, String search, String replace) {
        if (str == null || search == null || replace == null) {
            return str;
        }
        StringBuilder sb = new StringBuilder();
        int searchLen = search.length();
        int stringLen = str.length();
        int oldIndex = 0;
        int index;
        while ((index = str.indexOf(search, oldIndex)) >= 0) {
            sb.append(str, oldIndex, index);
            sb.append(replace);
            oldIndex = index + searchLen;
        }
        if (oldIndex < stringLen) {
            sb.append(str, oldIndex, stringLen);
        }
        return sb.toString();
    }
366449
static String escape(String value) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            String replacement = REPLACEMENTS.get(c);
            if (replacement != null) {
                builder.append(replacement);
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    }
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; 
            }
        }
470261
public List<String> getCellValues(String regex, List<ReplacePattern> replaces,
            boolean excludeEmptyValue) {
        List<String> valueList = new ArrayList<String>();

        if (StringUtils.isEmpty(regex)) {
            LOG.warn("列名が空であるセル値は格納できません。");
            return valueList;
        }
        Pattern pattern = Pattern.compile(regex);
        for (Entry<String, String> entry : getData().entrySet()) {
            if (pattern.matcher(entry.getKey()).matches()) {
                if (excludeEmptyValue && StringUtils.isEmpty(entry.getValue())) {
                    continue;
                }
                String value = value(entry.getValue(), replaces);
                LOG.trace("key:{}, value:{}", entry.getKey(), value);
                valueList.add(value);
            }
        }

        return valueList;
    }
1173090
protected void replaceValue(Map<String, Object> content, String key, Object value) {
		if (content.containsKey(key) && value != null) {
			content.put(key, value);
		}
	}
807574
private String stringReplace(String text, String target, String replacement) {
		return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(
				text).replaceAll(replacement);
	}
959889
public static boolean isValidStringMatchingRegex(final String value, final String expression) {

		Pattern pattern = patterns.get(expression);

		if (pattern == null) {

			pattern = Pattern.compile(expression);
			patterns.put(expression, pattern);
		}

		return (value != null && pattern.matcher(value).matches());
	}
968249
public Map<String, String> getCellValuesAsMap(String regex, int groupIdx,
            List<ReplacePattern> replaces) {
        Map<String, String> map = new TreeMap<String, String>();

        Pattern pattern = Pattern.compile(regex);
        for (Entry<String, String> entry : getData().entrySet()) {
            Matcher matcher = pattern.matcher(entry.getKey());

            if (matcher.matches()) {
                String value = value(entry.getValue(), replaces);
                map.put(matcher.group(groupIdx), value);
            }
        }
        return map;
    }
791179
@Deprecated
  public static PactDslRootValue stringMatcher(String regex) {
    PactDslRootValue rootValue = new PactDslRootValue();
    rootValue.generators.addGenerator(Category.BODY, "", new RegexGenerator(regex));
    rootValue.setValue(new Generex(regex).random());
    rootValue.setMatcher(rootValue.regexp(regex));
    return rootValue;
  }
613247
public static String replaceAll(CharSequence str, String regex, Func1<Matcher, String> replaceFun) {
		return replaceAll(str, Pattern.compile(regex), replaceFun);
	}
322051
public static boolean valueMatchesRegularExpression(String val, String regexp) {
		Pattern p = cache.get(regexp);
		if(p == null) {
			p = Pattern.compile(regexp);
			cache.put(regexp, p);
		}
		return valueMatchesRegularExpression(val, p);
	}
640394
protected static String parseFoundKey(String value) {
        //   System.out.println("Start Value: " + value);

        String regex = "#\\{([A-Za-z]+\\.)?([^\\}]+)\\}";
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(value);
        while (matcher.find()) {
            //         System.out.print("Start index: " + matcher.start());
            //         System.out.print(" End index: " + matcher.end() + " \n");
            String keyMatched = matcher.group().trim();
            //         System.out.println("Key: " + keyMatched);
            String trimmedKey = StringUtils.substring(keyMatched, 2, keyMatched.length() - 1);
            //         System.out.println("Trimmed Key: " + trimmedKey);
            String replacedValue = fetchString(trimmedKey);
            //         System.out.println("Replaced Value: " + replacedValue);
            if (StringUtils.contains(replacedValue, "#{")) {
                replacedValue = parseFoundKey(replacedValue);
            }
            value = StringUtils.replace(value, keyMatched, replacedValue);
            //         System.out.println("New Value: " + value);


        }
        return value;
    }