Prepare string to be passed through RegExp constructor while transforming
glob patterns.
185351
function preparePatternStringSegment(str) {
    if (STRING_TESTS.ARRAY.test(str)) {
        const els = str.replace(/([^\\]),/g, "$1$1,")
                       .split(/[^\\],/);
        return arrayToORRegExpStr(els.map(_transformSegment))
    } else {
        return _transformSegment(str);
    }
}
874396
function asRegExp(pattern) {
  // if regex then return it
  if (isRegExp(pattern)) {
    return pattern;
  }

  // if string then test for valid regex then convert to regex and return
  const match = pattern.match(REGEX);
  if (match) {
    return new RegExp(match[1], match[2]);
  }

  return new RegExp(pattern);
}
990339
private Pattern makePattern(String noProxy) {
        String regex = noProxy.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*");
        if (!regex.startsWith(".*")) {
            regex = ".*" + regex;
        }
        regex = "^" + regex + "$";
        return Pattern.compile(regex);
    }
504047
function createRegExp (regexp, options) {
    return new DuckType({
      name: options && options.name || null,
      test: function (object) {
        return ((object instanceof String) || typeof(object) === 'string') && regexp.test(object);
      }
    });
  }
612105
function fromString(str) {
  let 
    tmp = str.match(regexLatLon),
    converted = null;

  // Format: "latitude, longitude"
  if (tmp !== null) {
    converted = toCoordinate(tmp[1], tmp[2]);
  }
  // Format: "<geohash>"
  else if (regexGeohash.test(str)) {
    tmp = geohash.decode(str);
    converted = toCoordinate(tmp.latitude, tmp.longitude);
  }

  return converted;
}
995410
def regexp(input, **params):
    
    PARAM_FIELD_TO_PARSE = 'input.field'
    PARAM_PATTERN = 'pattern'
    PARAM_OUTPUT = 'output'
    OUT_DESC_FIELD = 'field'
    OUT_DESC_IDX = 'idx'
    OUT_DESC_TYPE = 'type'

    res = []
    regex = re.compile(params.get(PARAM_PATTERN))
    field2parse = params.get(PARAM_FIELD_TO_PARSE)
    out_desc = params.get(PARAM_OUTPUT)
    for row in input:
        matches = regex.findall(row[field2parse])[0]
        obj = {}
        for desc in out_desc:
            obj[desc[OUT_DESC_FIELD]] = Converter.convert(matches[desc[OUT_DESC_IDX]], desc[OUT_DESC_TYPE])
        res.append(obj)
    return res
860281
private static void do_replace(GlobData rdata, Context cx,
                                   RegExpImpl regExpImpl)
    {
        StringBuilder charBuf = rdata.charBuf;
        int cp = 0;
        String da = rdata.repstr;
        int dp = rdata.dollar;
        if (dp != -1) {
            int[] skip = new int[1];
            do {
                int len = dp - cp;
                charBuf.append(da.substring(cp, dp));
                cp = dp;
                SubString sub = interpretDollar(cx, regExpImpl, da,
                                                dp, skip);
                if (sub != null) {
                    len = sub.length;
                    if (len > 0) {
                        charBuf.append(sub.str, sub.index, sub.index + len);
                    }
                    cp += skip[0];
                    dp += skip[0];
                } else {
                    ++dp;
                }
                dp = da.indexOf('$', dp);
            } while (dp >= 0);
        }
        int daL = da.length();
        if (daL > cp) {
            charBuf.append(da.substring(cp, daL));
        }
    }
606825
def as_regexp(options = {})
      unless options.is_a?(::Hash)
        raise ::ArgumentError, "[to_regexp] Options must be a Hash"
      end
      str = self

      return if options[:detect] and str == ''

      if options[:literal] or (options[:detect] and ToRegexp::String.literal?(str))
        content = ::Regexp.escape str
      elsif delim_set = REGEXP_DELIMITERS.detect { |k, _| str.start_with?(k) }
        delim_start, delim_end = delim_set
        /\A#{delim_start}(.*)#{delim_end}(#{INLINE_OPTIONS})\z/u =~ str
        content = $1
        inline_options = $2
        return unless content.is_a?(::String)
        content.gsub! '\\/', '/'
        if inline_options
          options[:ignore_case] = true if inline_options.include?('i')
          options[:multiline] = true if inline_options.include?('m')
          options[:extended] = true if inline_options.include?('x')
          # 'n', 'N' = none, 'e', 'E' = EUC, 's', 'S' = SJIS, 'u', 'U' = UTF-8
          options[:lang] = inline_options.scan(/[nesu]/i).join.downcase
        end
      else
        return
      end
      
      ignore_case = options[:ignore_case] ? ::Regexp::IGNORECASE : 0
      multiline = options[:multiline] ? ::Regexp::MULTILINE : 0
      extended = options[:extended] ? ::Regexp::EXTENDED : 0
      lang = options[:lang] || ''
      if ::RUBY_VERSION > '1.9' and lang.include?('u')
        lang = lang.delete 'u'
      end
      
      if lang.empty?
        [ content, (ignore_case|multiline|extended) ]
      else
        [ content, (ignore_case|multiline|extended), lang ]
      end
    end
405480
function toRegexpSource(val, keys, options) {
  if (Array.isArray(val)) {
    return arrayToRegexp(val, keys, options);
  }

  if (val instanceof RegExp) {
    return regexpToRegexp(val, keys, options);
  }

  return stringToRegexp(val, keys, options);
}
440301
private String convertString(String str, String format, String expr)
    {
        String ret = str;

        String[] params = null;
        if(format.length() > 0)
        {
            ret = "";
            if(expr.length() > 0) // Indicates a format using regex
            {

                Pattern pattern = getPattern(expr);
                Matcher m = pattern.matcher(str);
                if(m.find())
                {
                    params = new String[m.groupCount()];
                    for(int i = 0; i < m.groupCount(); i++)
                        params[i] = m.group(i+1);
                }
            }
            else if(str != null)
            {
                params = new String[]{str};
            }

            if(params != null)
                ret = String.format(format, params);
        }

        return ret;
    }
108843
function format(str, args) {
        var keys = Object.keys(args), i;
        for (i=0; i<keys.length; i++) {
            str = str.replace(new RegExp("\\{" + keys[i] + "\\}", "gi"), args[keys[i]]);
        }
        return str;
    }
1242663
private static void replace_glob(GlobData rdata, Context cx,
                                     Scriptable scope, RegExpImpl reImpl,
                                     int leftIndex, int leftlen)
    {
        int replen;
        String lambdaStr;
        if (rdata.lambda != null) {
            // invoke lambda function with args lastMatch, $1, $2, ... $n,
            // leftContext.length, whole string.
            SubString[] parens = reImpl.parens;
            int parenCount = (parens == null) ? 0 : parens.length;
            Object[] args = new Object[parenCount + 3];
            args[0] = reImpl.lastMatch.toString();
            for (int i=0; i < parenCount; i++) {
                SubString sub = parens[i];
                if (sub != null) {
                    args[i+1] = sub.toString();
                } else {
                    args[i+1] = Undefined.instance;
                }
            }
            args[parenCount+1] = Integer.valueOf(reImpl.leftContext.length);
            args[parenCount+2] = rdata.str;
            // This is a hack to prevent expose of reImpl data to
            // JS function which can run new regexps modifing
            // regexp that are used later by the engine.
            // TODO: redesign is necessary
            if (reImpl != ScriptRuntime.getRegExpProxy(cx)) Kit.codeBug();
            RegExpImpl re2 = new RegExpImpl();
            re2.multiline = reImpl.multiline;
            re2.input = reImpl.input;
            ScriptRuntime.setRegExpProxy(cx, re2);
            try {
                Scriptable parent = ScriptableObject.getTopLevelScope(scope);
                Object result = rdata.lambda.call(cx, parent, parent, args);
                lambdaStr = ScriptRuntime.toString(result);
            } finally {
                ScriptRuntime.setRegExpProxy(cx, reImpl);
            }
            replen = lambdaStr.length();
        } else {
            lambdaStr = null;
            replen = rdata.repstr.length();
            if (rdata.dollar >= 0) {
                int[] skip = new int[1];
                int dp = rdata.dollar;
                do {
                    SubString sub = interpretDollar(cx, reImpl, rdata.repstr,
                                                    dp, skip);
                    if (sub != null) {
                        replen += sub.length - skip[0];
                        dp += skip[0];
                    } else {
                        ++dp;
                    }
                    dp = rdata.repstr.indexOf('$', dp);
                } while (dp >= 0);
            }
        }

        int growth = leftlen + replen + reImpl.rightContext.length;
        StringBuilder charBuf = rdata.charBuf;
        if (charBuf == null) {
            charBuf = new StringBuilder(growth);
            rdata.charBuf = charBuf;
        } else {
            charBuf.ensureCapacity(rdata.charBuf.length() + growth);
        }

        charBuf.append(reImpl.leftContext.str, leftIndex, leftIndex + leftlen);
        if (rdata.lambda != null) {
            charBuf.append(lambdaStr);
        } else {
            do_replace(rdata, cx, reImpl);
        }
    }
366373
function stringToRegexp (path, keys, options) {
	  var tokens = parse(path)
	  var re = tokensToRegExp(tokens, options)
	
	  // Attach keys back to the regexp.
	  for (var i = 0; i < tokens.length; i++) {
	    if (typeof tokens[i] !== 'string') {
	      keys.push(tokens[i])
	    }
	  }
	
	  return attachKeys(re, keys)
	}
874788
function cloneRegExp(input) {
    'use strict';
    var pattern = input.source;
    var flags = '';
    if (input.global) {
        flags += 'g';
    }
    if (input.ignoreCase) {
        flags += 'i';
    }
    if (input.multiline) {
        flags += 'm';
    }
    return (new RegExp(pattern, flags));
}
977344
def prepare_input(self, extracted_str):
        

        # Remove withspace
        if self.options['remove_whitespace']:
            optimized_str = re.sub(' +', '', extracted_str)
        else:
            optimized_str = extracted_str

        # Remove accents
        if self.options['remove_accents']:
            optimized_str = unidecode(optimized_str)

        # convert to lower case
        if self.options['lowercase']:
            optimized_str = optimized_str.lower()

        # specific replace
        for replace in self.options['replace']:
            assert len(replace) == 2, 'A replace should be a list of 2 items'
            optimized_str = optimized_str.replace(replace[0], replace[1])

        return optimized_str
227528
def prep_patterns(filenames):
    """"""

    patterns = []

    for filename in filenames:
        try:
            with open(filename) as file:
                patterns += [l.rstrip('\n') for l in file]
        except:  # pylint: disable=W0702
            LOGGER.error("Unable to load pattern file '%s'" % filename)
            sys.exit(1)

    if patterns:
        # return a set to eliminate duplicates
        return set(patterns)
    else:
        LOGGER.error('No terms were loaded')
        sys.exit(1)
677190
function createRegex(value, modifier) {
    if (Type.isString(value)) {
        return new RegExp(value, modifier ? modifier : 'g');
    }
    throw new Error('Core.createRegex: Value is not string');
}