find and replace any variables in the form
519058
private String replaceVariablesWithPatterns(String pattern) {
        int group = 0;
        Matcher findVariablesMatcher = variablePattern.matcher(pattern);
        while(findVariablesMatcher.find()) {
            String variable = findVariablesMatcher.group(0);
            pattern = pattern.replaceFirst(variable, "(.+)");
            variableToGroupNumber.put(variable, ++group);
        }
        return pattern;
    }
757920
def replace(self, request, id):
        """"""
        try:
            object = self.model.objects.get(id=id)
        except self.model.DoesNotExist:
            return self._render(
                request = request,
                template = '404',
                context = {
                    'error': 'The %s could not be found.' % self.model.__name__.lower()
                },
                status = 404,
                prefix_template_path = False
            )

        form = (self.form or generate_form(self.model))(request.PUT, instance=object)

        if form.is_valid():
            object = form.save()

            return self.show(request, id)
        else:
            return self._render(
                request = request,
                template = 'edit',
                context = {
                    'form': form
                },
                status = 400
            )
819727
function variables(root, config, done) {
  var expression = /\$v\[(.+?)\]/g;
  each(Object.keys(root), function(key, next) {
    var value = root[key];
    if (typeof value === 'object') return variables(value, config, next);
    if (typeof value !== 'string') return next();
    root[key] = value.replace(expression, function(match, matchKey) {
      return config[matchKey] || match;
    });
    next();
  }, done);
}
1068339
function replacer() {
      // don't do any replacing if the user supplied no values
      if (!opts.values.length)
        return arguments[0];

      var ix = arguments.length > 3 ? parseInt(arguments[1], 10) : opts.value_ix++;
      var val = opts.values[ix - 1];
      if (_.isUndefined(val))
        throw new Error('Parameterized sql() (' + str + ') requires ' + ix + ' parameter(s) but only ' + opts.values.length + ' parameter(s) were supplied');
      if (_.isObject(sql) && !_.isArray(sql) && sql == null)
        return val.toString(opts);
      else
        return sql.convert(val);
    }
682434
private function replace_var( $matches ) {
		$cmd = $matches[0];

		foreach ( array_slice( $matches, 1 ) as $key ) {
			$cmd = str_replace( '{' . $key . '}', $this->variables[ $key ], $cmd );
		}

		return $cmd;
	}
832750
def replace_content(content, project_vars):
    

    for k, v in project_vars.items():
        content = content.replace(f'__{k}__', v)

    return content
583715
private function setFormName() : void
    {
        $this->key = 'form_' . $this->name . '_' . bin2hex(random_bytes(16));

        // Form key must be unique
        if (isset($_SESSION[$this->key])) {
            $this->setFormName();
        }

        // Remove potential previous form with same name from session
        $prev_form_keys = preg_grep('/^form_' . preg_quote($this->name, '/') . '_[a-f0-9]+$/', array_keys($_SESSION));
        array_map(function ($key) {
            unset($_SESSION[$key]);
        }, $prev_form_keys);

        // Save the new form
        $_SESSION[$this->key] = [];
    }
23898
def _replace(variables, match):
    
    expression = match.group(1)

    # Look-up chars and functions for the specified operator
    (prefix_char, separator_char, split_fn, escape_fn,
     format_fn) = operator_map.get(expression[0], defaults)

    replacements = []
    for key, modify_fn, explode in split_fn(expression):
        if key in variables:
            variable = modify_fn(variables[key])
            replacement = format_fn(
                explode, separator_char, escape_fn, key, variable)
            replacements.append(replacement)
    if not replacements:
        return ''
    return prefix_char + separator_char.join(replacements)
444635
def inputs(form_args):
    
    element = []
    for name, value in form_args.items():
        element.append(
            '<input type="hidden" name="{}" value="{}"/>'.format(name, value))
    return "\n".join(element)
231781
def translate(self):
        """"""
        ident = self.ident
        expr = ex_rvalue(VARIABLE_PREFIX + ident)
        return [expr], set([ident]), set()
739102
public static String substitute(String input, List<VariableInstance> variables)
    throws MdwException {
        StringBuffer substituted = new StringBuffer(input.length());
        try {
            Matcher matcher = tokenPattern.matcher(input);
            int index = 0;
            while (matcher.find()) {
                String match = matcher.group();
                substituted.append(input.substring(index, matcher.start()));
                Object value = getVariableValue(match.substring(2, match.length() - 1), variables);
                if (value != null)
                    substituted.append(value);
                index = matcher.end();
            }
            substituted.append(input.substring(index));
            return substituted.toString();
        }
        catch (Exception ex) {
            throw new MdwException("Error substituting expression value(s) in input: '" + input + "'", ex);
        }
    }
148044
def replace_variable(self, variable):
        """"""
        if variable == 'x':
            return self.value
        if variable == 't':
            return self.timedelta
        raise ValueError("Invalid variable %s", variable)
1093876
def replaceVariables(path, datetime=None, pathvars=None):
    """"""

    if datetime is None:
        datetime = time.gmtime()

    # if path variables are not given, set as empty list
    if pathvars is None:
        pathvars = [ ]

    # create an init path list to loop through
    if isinstance(path, list):
        path_list = path
    else:
        path_list = [ path ]

    # Set up the regex to search for variables
    regex = re.compile('\$\{(.*?)\}')

    # create a newpath list that will hold the 'cleaned' paths
    # with variables and strftime format directives replaced
    newpath_list = [ ]

    for p in path_list:
        # create temppath_list to be used a we work through the
        newpath_list.append(p)

        # Variable replacement
        # Find all the variables in path using the regex
        for k in regex.findall(p):
            # Check if the key is in path variables map
            if k in pathvars:
                # get the str or list of values
                v = pathvars[k]

                # Check value of variable must be in (string, integer, list)
                if type(v) is dict:
                    msg = "Path variable must refer to string, integer, or list"
                    raise TypeError(msg)

                # get the list of possible variable values
                value_list = v if type(v) is list else [ v ]


                # create temp_list for now
                temp_list = []

                # loop through the most recent newpath list
                # need to do this every time in order to account for all possible
                # combinations
                # replace the variables
                # loop through the list of values and replace the variables
                for v in value_list:
                    for newpath in newpath_list:
                        # remove the path from newpath_list
                        temp_list.append(newpath.replace('${%s}' % k, str(v)))

                # replace newpath_list
                newpath_list = temp_list

        # strftime translation
        # Loop through newpath_list to do strftime translation
        for index, newpath in enumerate(newpath_list):
            # Apply strftime translation
            newpath_list[index] = time.strftime(newpath, datetime)

    return newpath_list
764018
public static String replaceVariables( final VariableResolver pResolver, final String pExpression, final String pOpen, final String pClose ) {
        final char[] open = pOpen.toCharArray();
        final char[] close = pClose.toCharArray();

        final StringBuilder out = new StringBuilder();
        StringBuilder sb = new StringBuilder();
        char[] last = null;
        int wo = 0;
        int wc = 0;
        int level = 0;
        for (char c : pExpression.toCharArray()) {
            if (c == open[wo]) {
                if (wc > 0) {
                    sb.append(close, 0, wc);
                }
                wc = 0;
                wo++;
                if (open.length == wo) {
                    // found open
                    if (last == open) {
                        out.append(open);
                    }
                    level++;
                    out.append(sb);
                    sb = new StringBuilder();
                    wo = 0;
                    last = open;
                }
            } else if (c == close[wc]) {
                if (wo > 0) {
                    sb.append(open, 0, wo);
                }
                wo = 0;
                wc++;
                if (close.length == wc) {
                    // found close
                    if (last == open) {
                        final String variable = pResolver.get(sb.toString());
                        if (variable != null) {
                            out.append(variable);
                        } else {
                            out.append(open);
                            out.append(sb);
                            out.append(close);
                        }
                    } else {
                        out.append(sb);
                        out.append(close);
                    }
                    sb = new StringBuilder();
                    level--;
                    wc = 0;
                    last = close;
                }
            } else {

                if (wo > 0) {
                    sb.append(open, 0, wo);
                }

                if (wc > 0) {
                    sb.append(close, 0, wc);
                }

                sb.append(c);

                wo = wc = 0;
            }
        }

        if (wo > 0) {
            sb.append(open, 0, wo);
        }

        if (wc > 0) {
            sb.append(close, 0, wc);
        }

        if (level > 0) {
            out.append(open);
        }
        out.append(sb);

        return out.toString();
    }
913329
protected function replaceWithVariables($string)
    {
        if (preg_match_all('/:([a-z_]+)/', $string, $matches)) {
            list(
                $original,
                $vars
            ) = $matches;

            foreach ($vars as $key => $var) {
                if (isset($this->vars[$var])) {
                    $string = str_replace($original[$key], $this->vars[$var], $string);
                }
            }
        }

        return $string;
    }
784397
def form_fields(self):
        

        fields = dict(self.form.fields) # pylint: disable=no-member

        fields_to_remove = set()

        for key, val in list(fields.items()):
            if isinstance(val, CheckboxValues):
                if not len(val): # pylint: disable=len-as-condition
                    del fields[key]
                elif len(val) == 1:
                    fields[key] = val.pop()
                else:
                    fields[key] = list(val)
            if isinstance(val, MultipleSelectOptions):
                if not len(val): # pylint: disable=len-as-condition
                    del fields[key]
                elif len(val) == 1:
                    fields[key] = val.pop()
                else:
                    fields[key] = list(val)

        for elem in self.form.inputs: # pylint: disable=no-member
            # Ignore elements without name
            if not elem.get('name'):
                continue

            # Do not submit disabled fields
            # http://www.w3.org/TR/html4/interact/forms.html#h-17.12
            if elem.get('disabled'):
                if elem.name in fields:
                    fields_to_remove.add(elem.name)
            elif getattr(elem, 'type', None) == 'checkbox':
                if not elem.checked:
                    if elem.name is not None:
                        if elem.name in fields and fields[elem.name] is None:
                            fields_to_remove.add(elem.name)
            else:
                if elem.name in fields_to_remove:
                    fields_to_remove.remove(elem.name)
                if elem.tag == 'select':
                    if elem.name in fields and fields[elem.name] is None:
                        if elem.value_options:
                            fields[elem.name] = elem.value_options[0]

                elif getattr(elem, 'type', None) == 'radio':
                    if fields[elem.name] is None:
                        fields[elem.name] = elem.get('value')
        for fname in fields_to_remove:
            del fields[fname]
        return fields
289487
public function replaceWithVariables($string)
    {
        $matches = null;
        $matcher = preg_match_all($this->regex, $string, $matches);

        $original = $matches[0];
        $vars     = $matches[1];

        foreach ($vars as $key => $variable) {
            if ($attribute = $this->getAttribute($variable)) {
                $string = str_replace($original[$key], $attribute, $string);
            }
        }

        return $string;
    }