> regex_for_range(12, 345)
    '1[2-9]|[2-9]\d|[1-2]\d{2}|3[0-3]\d|34[0-5]'
482648
def regex_for_range(min_, max_):
    
    positive_subpatterns = []
    negative_subpatterns = []
    max_ -= 1
    if min_ < 0:
        min__ = 1
        if max_ < 0:
            min__ = abs(max_)
        max__ = abs(min_)

        negative_subpatterns = split_to_patterns(min__, max__)
        min_ = 0

    if max_ >= 0:
        positive_subpatterns = split_to_patterns(min_, max_)    

    negative_only_subpatterns = ['-' + val for val in negative_subpatterns if val not in positive_subpatterns]
    positive_only_subpatterns = [val for val in positive_subpatterns if val not in negative_subpatterns]
    intersected_subpatterns = ['-?' + val for val in negative_subpatterns if val in positive_subpatterns]

    subpatterns = negative_only_subpatterns + intersected_subpatterns + positive_only_subpatterns
    return '|'.join(subpatterns)
1337863
function rangeFromIndexAndOffsets(i, before, after, length) {
  return {
    // Guard against the negative upper bound for lines included in the output.
    from: i - before > 0 ? i - before : 0,
    to: i + after > length ? length : i + after
  };
}
990205
def range(self):
        """"""
        match = self._match(in_comment(
            'n[ \t]+in[ \t]*\\[([0-9]+)\\.\\.([0-9]+)\\),[ \t]+'
            'step[ \t]+([0-9]+)'
        ))
        return range(
            int(match.group(1)),
            int(match.group(2)),
            int(match.group(3))
        )
367583
def parse_range_header(range):
    '''
    
    '''
    match = re.match('^items=([0-9]+)-([0-9]+)$', range)
    if match:
        start = int(match.group(1))
        finish = int(match.group(2))
        if finish < start:
            finish = start
        return {
            'start': start,
            'finish': finish,
            'number': finish - start + 1
        }
    else:
        return False
396770
function rangeFromMatch(match) {
        var wrappers = getWrappersByIndex(indexOf(match));

        var rng = editor.dom.createRng();
        rng.setStartBefore(wrappers[0]);
        rng.setEndAfter(wrappers[wrappers.length - 1]);

        return rng;
      }
222211
def range_fltr(dem, rangelim):
    
    print('Excluding values outside of range: {0:f} to {1:f}'.format(*rangelim))
    out = np.ma.masked_outside(dem, *rangelim)
    out.set_fill_value(dem.fill_value)
    return out
62948
def parse_range_pairs(s, range_separator = '-', convert_to_tuple = True):
    ''' 
    '''
    result = map(sorted,
       map(lambda r:
            (int(r.split(range_separator)[0]), int(r.split(range_separator)[1])) if range_separator in r
            else (int(r), int(r)),
            s.split(',')))
    if convert_to_tuple:
        return tuple(map(tuple, result))
    return result
65975
def string_range(last):
    
    for k in range(len(last)):
        for x in product(string.ascii_lowercase, repeat=k+1):
            result = ''.join(x)
            yield result
            if result == last:
                return
850452
def summarize_ranges(array):
    
    res = []
    if len(array) == 1:
        return [str(array[0])]
    i = 0
    while i < len(array):
        num = array[i]
        while i + 1 < len(array) and array[i + 1] - array[i] == 1:
            i += 1
        if array[i] != num:
            res.append((num, array[i]))
        else:
            res.append((num, num))
        i += 1
    return res
511439
def get_number_matches(self, pattern, source_text='', case=False,
                           regexp=False):
        """"""
        pattern = to_text_string(pattern)
        if not pattern:
            return 0

        if not regexp:
            pattern = re.escape(pattern)

        if not source_text:
            source_text = to_text_string(self.toPlainText())

        try:
            if case:
                regobj = re.compile(pattern)
            else:
                regobj = re.compile(pattern, re.IGNORECASE)
        except sre_constants.error:
            return None

        number_matches = 0
        for match in regobj.finditer(source_text):
            number_matches += 1

        return number_matches
371798
function fillRange(value) {
  var start = value.split('~')[0];
  var end   = value.split('~')[1];

  var decimals = (start.split('.')[1] || '').length;
  var mult = Math.pow(10, decimals);

  var range = _.range(start * mult, end * mult + 1)
                  // round errors to required decimal precision
                  .map(function (val) {
                    return (val / mult).toFixed(decimals);
                  });

  var last = range[range.length - 1];

  // Stupid self check
  if (+end !== +last) {
    throw new Error(format('Range create error for %s: last value is %s', value, last));
  }

  // Now we have array of string samples. Add integers when possible.
  var result = [];

  range.forEach(function (val) {
    // push test data as String
    result.push(val);
    // push test data as Number if the same
    if (String(+val) === val) { result.push(+val); }
  });

  return result;
}
93792
def _regexp(expr, item):
    ''' 
    '''
    reg = re.compile(expr)
    return reg.search(item) is not None
256604
function regex2value(value) {

        // highly sensitive!! Do not change this without running the
        // Protocol/HTTP.html unit tests

        // convert % to \%
        value = value.replace(/%/g, "\\%");

        // convert \\. to \\_ (\\.* occurences converted later)
        value = value.replace(/\\\\\.(\*)?/g, function($0, $1) {
            return $1 ? $0 : "\\\\_";
        });

        // convert \\.* to \\%
        value = value.replace(/\\\\\.\*/g, "\\\\%");

        // convert . to _ (\. and .* occurences converted later)
        value = value.replace(/(\\)?\.(\*)?/g, function($0, $1, $2) {
            return $1 || $2 ? $0 : "_";
        });

        // convert .* to % (\.* occurnces converted later)
        value = value.replace(/(\\)?\.\*/g, function($0, $1) {
            return $1 ? $0 : "%";
        });

        // convert \. to .
        value = value.replace(/\\\./g, ".");

        // replace \* with * (watching out for \\*)
        value = value.replace(/(\\)?\\\*/g, function($0, $1) {
            return $1 ? $0 : "*";
        });

        return value;
    }
473033
def range(self, start='-', stop='+', count=None):
        
        return self.database.xrange(self.key, start, stop, count)
752745
def _split_regex(regex):
    
    if regex[0] == '^':
        regex = regex[1:]
    if regex[-1] == '$':
        regex = regex[0:-1]
    results = []
    line = ''
    for c in regex:
        if c == '(':
            results.append(line)
            line = ''
        elif c == ')':
            line = ''
        else:
            line = line + c
    if len(line) > 0:
        results.append(line)
    return results
1095608
def _format_finite(negative, digits, dot_pos):
    """"""

    # strip leading zeros
    olddigits = digits
    digits = digits.lstrip('0')
    dot_pos -= len(olddigits) - len(digits)

    # value is 0.digits * 10**dot_pos
    use_exponent = dot_pos <= -4 or dot_pos > len(digits)
    if use_exponent:
        exp = dot_pos - 1 if digits else dot_pos
        dot_pos -= exp

    # left pad with zeros, insert decimal point, and add exponent
    if dot_pos <= 0:
        digits = '0' * (1 - dot_pos) + digits
        dot_pos += 1 - dot_pos
    assert 1 <= dot_pos <= len(digits)
    if dot_pos < len(digits):
        digits = digits[:dot_pos] + '.' + digits[dot_pos:]
    if use_exponent:
        digits += "e{0:+03d}".format(exp)
    return '-' + digits if negative else digits
1197397
def validation_regex
      n = @kat.results[@page].size
      commands = "[#{ 'i' if hide_info? }#{ 'n' if next? }#{ 'p' if prev? }q]|"
      _01to09  = "[1-#{ [n, 9].min }]"
      _10to19  = "#{ "|1[0-#{ [n - 10, 9].min }]" if n >  9 }"
      _20to25  = "#{ "|2[0-#{ n - 20 }]" if n > 19 }"

      /^(#{ commands }#{ _01to09 }#{ _10to19 }#{ _20to25 })$/
    end