Makes a brush compatible with the `html-script` functionality.
@param {Object} regexGroup Object containing `left` and `right` regular expressions.
8922
function(regexGroup)
        {
            var regex = { 'end' : regexGroup.right.source };

            if(regexGroup.eof)
                regex.end = "(?:(?:" + regex.end + ")|$)";

            this.htmlScript = {
                left : { regex: regexGroup.left, css: 'script' },
                right : { regex: regexGroup.right, css: 'script' },
                code : new XRegExp(
                    "(?<left>" + regexGroup.left.source + ")" +
                        "(?<code>.*?)" +
                        "(?<right>" + regex.end + ")",
                    "sgi"
                )
            };
        }
630530
String regExpGroupName(String pkgName) {
        for (int j = 0; j < sortedRegExpList.size(); j++) {
            String regexp = sortedRegExpList.get(j);
            if (pkgName.startsWith(regexp)) {
                return regExpGroupMap.get(regexp);
            }
        }
        return null;
    }
1202288
public static Matcher findRegex(Object left, Object right) {
        String stringToCompare;
        if (left instanceof String) {
            stringToCompare = (String) left;
        } else {
            stringToCompare = toString(left);
        }
        String regexToCompareTo;
        if (right instanceof String) {
            regexToCompareTo = (String) right;
        } else if (right instanceof Pattern) {
            Pattern pattern = (Pattern) right;
            return pattern.matcher(stringToCompare);
        } else {
            regexToCompareTo = toString(right);
        }
        return Pattern.compile(regexToCompareTo).matcher(stringToCompare);
    }
359116
function formParagraphs(text) {

        text = text.replace(/^\n+/g,"");
        text = text.replace(/\n+$/g,"");

        var grafs = text.split(/\n{2,}/g);
        var grafsOut = new Array();
        var end = grafs.length;

        for(var i=0; i<end; i++) {
            var str = grafs[i];

            if(str.search(/~K(\d+)K/g) >= 0) {
                grafsOut.push(str);
            } else if (str.search(/\S/) >= 0) {
                str = runSpanGamut(str);
                str = str.replace(/^([ \t]*)/g,"<p>");
                str += "</p>"
                grafsOut.push(str);
            }

        }

        end = grafsOut.length;

        for(var i=0; i<end; i++) {
            while(grafsOut[i].search(/~K(\d+)K/) >= 0) {
                var blockText = htmlBlock[RegExp.$1];
                blockText = blockText.replace(/\$/g,"$$$$");
                grafsOut[i] = grafsOut[i].replace(/~K\d+K/,blockText);
            }
        }

        return grafsOut.join("\n\n");
    }
276886
function fixBadRegex(grammar) {
	const scopeResolution = grammar.repository['scope-resolution'];
	if (scopeResolution) {
		const match = scopeResolution.patterns[0].match;
		if (match === '(?i)([a-z_\\x{7f}-\\x{7fffffff}\\\\][a-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)') {
			scopeResolution.patterns[0].match = '([A-Za-z_\\x{7f}-\\x{7fffffff}\\\\][A-Za-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)';
			return;
		}
	}

	throw new Error(`fixBadRegex callback couldn't patch the regex. It may be obsolete`);
}
924772
function(regex) {
  var self = this; var re = new RegExp(regex);
  var keys = {};
  self.init = function() { keys = {}; };
  self.accumulate = function(line) {
    var m = re.exec(line);
    if (m == null) return;
    var k = m[1]; // use 1st group as key
    var v = keys[k];
    if (v) keys[k] = v+1; else keys[k] = 1; // count by key
  };
  self.compensate = function(line) {
    var m = re.exec(line);
    if (m == null) return;
    var k = m[1]; // use 1st group as key
    var v = keys[k];
    if (v) keys[k] = v-1; else keys[k] = 1;
  };
  self.emit = function() {
    return keys;
  };
  self.make = function() { return new WideFinderFunction(regex); };
}
773772
function makeGlobal(pattern) {
  var flags = 'g';

  if (pattern.multiline) flags += 'm';
  if (pattern.ignoreCase) flags += 'i';
  if (pattern.sticky) flags += 'y';
  if (pattern.unicode) flags += 'u';

  return new RegExp(pattern.source, flags);
}
606181
function (regexName, regex, content, results) {
      var r;
      _log.debug("---------------------------------------------------------------------------------------------------");
      _log.debug('Process extraction with regex : "' + regexName + '"');
      _log.debug(regex);
      regex.lastIndex = 0;
      while ((r = regex.exec(content)) !== null) {

        // Result expected [STRING, KEY, SOME_REGEX_STUF]
        // Except for plural hack [STRING, KEY, ARRAY_IN_STRING]
        if (r.length >= 2) {
          var translationKey, evalString;
          var translationDefaultValue = "";

          switch (regexName) {
            case 'HtmlDirectiveSimpleQuote':
            case 'HtmlDirectiveDoubleQuote':
              translationKey = r[1].trim();
              translationDefaultValue = (r[2] || "").trim();
              break;
            case 'HtmlDirectivePluralFirst':
              if (!r.length > 2) {
                return;
              }
              var tmp = r[1];
              r[1] = r[2];
              r[2] = tmp;
            case 'HtmlDirectivePluralLast':
              evalString = eval(r[2]);
              if (_.isArray(evalString) && evalString.length >= 2) {
                translationDefaultValue = "{NB, plural, one{" + evalString[0] + "} other{" + evalString[1] + "}" + (evalString[2] ? ' ' + evalString[2] : '') + "}";
              }
              translationKey = r[1].trim();
              break;
            default:
              translationKey = r[1].trim();
          }

          // Avoid empty translation
          if (translationKey === "") {
            return;
          }

          switch (regexName) {
            case "commentSimpleQuote":
            case "HtmlFilterSimpleQuote":
            case "JavascriptServiceSimpleQuote":
            case "JavascriptServiceInstantSimpleQuote":
            case "JavascriptFilterSimpleQuote":
            case "HtmlNgBindHtml":
              translationKey = translationKey.replace(/\\\'/g, "'");
              break;
            case "commentDoubleQuote":
            case "HtmlFilterDoubleQuote":
            case "JavascriptServiceDoubleQuote":
            case "JavascriptServiceInstantDoubleQuote":
            case "JavascriptFilterDoubleQuote":
              translationKey = translationKey.replace(/\\\"/g, '"');
              break;
            case "JavascriptServiceArraySimpleQuote":
            case "JavascriptServiceArrayDoubleQuote":
              var key;

              if(regexName === "JavascriptServiceArraySimpleQuote") {
                key = translationKey.replace(/'/g, '');
              } else {
                key = translationKey.replace(/"/g, '');
              }
              key = key.replace(/[\][]/g, '');
              key = key.split(',');

              key.forEach(function(item){
                item = item.replace(/\\\"/g, '"').trim();
                if (item !== '') {
                  results[item] = translationDefaultValue;
                }
              });
              break;
          }

          // Check for customRegex
          if (_.isObject(customRegex) && !_.isArray(customRegex) && customRegex.hasOwnProperty(regexName)) {
            if (_.isFunction(customRegex[regexName])) {
              translationKey = customRegex[regexName](translationKey) || translationKey;
            }
          }

          // Store the translationKey with the value into results
          var defaultValueByTranslationKey = function (translationKey, translationDefaultValue) {
            if (regexName !== "JavascriptServiceArraySimpleQuote" &&
              regexName !== "JavascriptServiceArrayDoubleQuote") {
              if (keyAsText === true && translationDefaultValue.length === 0) {
                results[translationKey] = translationKey;
              } else {
                results[translationKey] = translationDefaultValue;
              }
            }
          }

          // Ternary operation
          var ternaryKeys = _extractTernaryKey(translationKey)
          if (ternaryKeys) {
            _.forEach(ternaryKeys, function(v) {
              defaultValueByTranslationKey(v);
            });
          } else {
            defaultValueByTranslationKey(translationKey, translationDefaultValue);
          }

        }
      }
    }
456097
function (html) {
        var self = this;
        var matchedList = html.match(new RegExp(self.DEFINE_LEFT + '.+' + self.RIGHT, 'g'));
        matchedList = _.map(matchedList, function (matched) {
            return matched.substring(self.DEFINE_LEFT.length, matched.length - self.RIGHT.length);
        });
        return matchedList;
    }
584790
public static String regex_group(EvaluationContext ctx, Object text, Object pattern, Object groupNum) {
        String _text = Conversions.toString(text, ctx);
        String _pattern = Conversions.toString(pattern, ctx);
        int _groupNum = Conversions.toInteger(groupNum, ctx);

        try {
            // check whether we match
            int flags = Pattern.CASE_INSENSITIVE | Pattern.MULTILINE;
            Pattern regex = Pattern.compile(_pattern, flags);
            Matcher matcher = regex.matcher(_text);

            if (matcher.find()) {
                if (_groupNum < 0 || _groupNum > matcher.groupCount()) {
                    throw new RuntimeException("No such matching group " + _groupNum);
                }

                return matcher.group(_groupNum);
            }
        } catch (PatternSyntaxException ignored) {}

        return "";
    }
43018
function parseGroupExpression() {
        var expr, expressions, startToken, isValidArrowParameter = true;

        expect('(');

        if (match(')')) {
            lex();
            if (!match('=>')) {
                expect('=>');
            }
            return {
                type: PlaceHolders.ArrowParameterPlaceHolder,
                params: []
            };
        }

        startToken = lookahead;
        if (match('...')) {
            expr = parseRestElement();
            expect(')');
            if (!match('=>')) {
                expect('=>');
            }
            return {
                type: PlaceHolders.ArrowParameterPlaceHolder,
                params: [expr]
            };
        }

        if (match('(')) {
            isValidArrowParameter = false;
        }

        expr = parseAssignmentExpression();

        if (match(',')) {
            expressions = [expr];

            while (startIndex < length) {
                if (!match(',')) {
                    break;
                }
                lex();

                if (match('...')) {
                    if (!isValidArrowParameter) {
                        throwUnexpectedToken(lookahead);
                    }
                    expressions.push(parseRestElement());
                    expect(')');
                    if (!match('=>')) {
                        expect('=>');
                    }
                    return {
                        type: PlaceHolders.ArrowParameterPlaceHolder,
                        params: expressions
                    };
                } else if (match('(')) {
                    isValidArrowParameter = false;
                }

                expressions.push(parseAssignmentExpression());
            }

            expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
        }


        expect(')');

        if (match('=>') && !isValidArrowParameter) {
            throwUnexpectedToken(lookahead);
        }

        return expr;
    }
1162155
function trim(text) {
  var MAX_INDENT = 9999;
  var empty = RegExp.prototype.test.bind(/^\s*$/);
  var lines = text.split('\n');
  var minIndent = MAX_INDENT;
  var indentRegExp;
  var ignoreLine = (lines[0][0] != ' '  && lines.length > 1);
  // ignore first line if it has no indentation and there is more than one line

  lines.forEach(function(line){
    if (ignoreLine) {
      ignoreLine = false;
      return;
    }

    var indent = line.match(/^\s*/)[0].length;
    if (indent > 0 || minIndent == MAX_INDENT) {
      minIndent = Math.min(minIndent, indent);
    }
  });

  indentRegExp = new RegExp('^\\s{0,' + minIndent + '}');

  for ( var i = 0; i < lines.length; i++) {
    lines[i] = lines[i].replace(indentRegExp, '');
  }

  // remove leading lines
  while (empty(lines[0])) {
    lines.shift();
  }

  // remove trailing
  while (empty(lines[lines.length - 1])) {
    lines.pop();
  }
  return lines.join('\n');
}
590633
function make_regex(tokens) {
	var str = tokens.reduce(function (res, token, index) {
			var is_last = (index == (tokens.length - 1));
			var before_multi = (index === (tokens.length - 2)) && (last(tokens).type == "multi");
			return res + ((is_last || before_multi) ? token.last : token.piece);
		},
		"");
	return new RegExp("^" + str + "$");
}
1230104
function(){
            _.each(this.rules, function(rule){
                rule.regex = eval(rule.regex.toString().replace(/^\//,'/^'));
            });
        }
1367825
function finishGroup(&$group)
    {
        $separator = $group->_separator;
        if (is_array($separator)) {
            $count = count($separator);
            $html  = '';
            for ($i = 0; $i < count($this->_groupElements); $i++) {
                $html .= (0 == $i? '': $separator[($i - 1) % $count]) . $this->_groupElements[$i];
            }
        } else {
            if (is_null($separator)) {
                $separator = '&nbsp;';
            }
            $html = implode((string)$separator, $this->_groupElements);
        }
        if (!empty($this->_groupWrap)) {
            $html = str_replace('{content}', $html, $this->_groupWrap);
        }
        $this->_html   .= str_replace('{element}', $html, $this->_groupTemplate);
        $this->_inGroup = false;
    }
1173173
function removeComplete(regex, lines, start) {
  var matches = lines[start].match(regex);
  var i = 0;
  var s = lines[start];
  matches = s.match(regex);

  while (!matches) {
    i++;
    if ((start + i) > lines.length) return;
    s += lines[start + i];
    matches = s.match(regex);
  }
  lines.splice(start, i + 1);
}
952470
function (str, highlight) {
      highlight = highlight || false;
      var self = this;

      var highlightColor = this.highlightColor;
      var replace = function (str, pattern) {
        if (!highlight) {
          return str.replace(pattern, function (match) {
            self.currentMatch.matches.push(match);
            return self.replacementString;
          });
        }

        return str.replace(pattern, function (match) {
          self.currentMatch.matches.push(match);
          return '<span style="background: #' + highlightColor + ';">' + match + '</span>';
        });
      }.bind(this);

      if (typeof str !== 'string') {
        throw 'Invalid "str" type supplied in filterString. Expected string.';
      }

      for (var p in this.patterns) {
        if (!this.patterns[p].enabled) {
          continue;
        }

        if (this.patterns[p].pattern instanceof RegExp) {
          str = replace(str, this.patterns[p].pattern);

          continue;
        }

        if (!this.isArray(this.patterns[p].pattern)) {
          throw 'Invalid pattern type supplied. Expected Array.';
        }

        for (var i = 0; i < this.patterns[p].pattern.length; i++) {
          if (!this.patterns[p].pattern[i] instanceof RegExp) {
            throw 'Expected valid RegExp.';
          }

          str = replace(str, this.patterns[p].pattern[i]);
        }
      }

      return str;
    }