jump to previous occurence of given regexp within a line, and then to previous line
   This is more line 'w' or 'b' in vim, not like '/'
 @param [Regexp] pattern to go back to.
324613
def backward_regex regex
      if regex.is_a? Symbol
        regex = @text_patterns[regex]
        raise "Pattern specified #{regex} does not exist in text_patterns " unless regex
      end
      $multiplier = 1 if !$multiplier || $multiplier == 0
      _arr = _getarray
      pos = @curpos || 0 # list does not have curpos
      line = @current_index
      #buff = _arr[line].to_s
      #return unless buff
      # if curpos is at zero , we should be checking previous line !
      $multiplier.times {
        # if at start of line, go to previous line
        if pos == 0
          if @current_index > 0
            line -= 1
            pos = _arr[line].to_s.size
          else
            # we are on first line of file at start
            break
          end
        end
        buff = _arr[line].to_s
        return unless buff
        pos2 = pos - 2
        pos2 = 0 if pos2 < 0
        found = buff.rindex(regex, pos2)
        $log.debug "  backward: pos #{pos} , found #{found}, pos2 = #{pos2} "
        if !found || found == 0
          # if not found, we've lost a counter
          if pos > 0
            pos = 0
          elsif line > 0
            #line -= 1
            #pos = _arr[line].to_s.size
          else
            break
          end
        else
          pos = found + 1
        end
        $log.debug " backward_word: pos #{pos} line #{line} buff: #{buff}"
      }
      $multiplier = 0
      @current_index = line
      @curpos = pos
      ensure_visible
      @repaint_required = true
    end
1351871
def _prepare_pattern(self, pattern):
        
        regex, _, rest = pattern.partition('\\;')
        try:
            return re.compile(regex, re.I)
        except re.error as e:
            warnings.warn(
                "Caught '{error}' compiling regex: {regex}"
                .format(error=e, regex=regex)
            )
            # regex that never matches:
            # http://stackoverflow.com/a/1845097/413622
            return re.compile(r'(?!x)x')
696151
def _next_pattern(self):
        """"""
        current_state = self.state_stack[-1]
        position = self._position
        for pattern in self.patterns:
            if current_state not in pattern.states:
                continue

            m = pattern.regex.match(self.source, position)
            if not m:
                continue

            position = m.end()
            token = None

            if pattern.next_state:
                self.state_stack.append(pattern.next_state)

            if pattern.action:
                callback = getattr(self, pattern.action, None)
                if callback is None:
                    raise RuntimeError(
                        "No method defined for pattern action %s!" %
                        pattern.action)

                if "token" in m.groups():
                    value = m.group("token")
                else:
                    value = m.group(0)
                token = callback(string=value, match=m,
                                 pattern=pattern)

            self._position = position

            return token

        self._error("Don't know how to match next. Did you forget quotes?",
                    start=self._position, end=self._position + 1)
627686
function(regex){
		//if it isn't global, `exec()` will not start at `lastIndex`
		if(!regex.global)
			regex.compile(regex.source, flags(regex));
		regex.lastIndex = this.position;
		var m = regex.exec(this.source);

		//all matches must start at the current position.
		if(m && m.index!=this.position){
			return null;
		}

		if(m) this.position += m[0].length;
		return m;
	}
1295196
private String cutAfterTab(String line) {
        Pattern p = Pattern.compile("^(.*)\\t.*$");
        Matcher matcher = p.matcher(line);
        if (matcher.matches()) {
            return matcher.group(1);
        } else {
            return line;
        }
    }
931323
public void setRegexp(final String pRegexp)
    {
        if (pRegexp != null && pRegexp.length() > 0) {
            regexp = Pattern.compile(pRegexp);
        }
    }
952130
function(regex, text){
    var nextIndex = 0;
    var result = [];

    var execResult;
    while ((execResult = regex.exec(text))!== null) {
        result.push({
            start: execResult.index, 
            matchLength: execResult[0].length});
    }

    return {
        next: function(){
            return nextIndex < result.length ?
                result[nextIndex++] :
                null;
        }
    };
}
811716
def _expect_inline_link(text, start):
    """"""
    if start >= len(text) or text[start] != '(':
        return None
    i = start + 1
    m = patterns.whitespace.match(text, i)
    if m:
        i = m.end()
    m = patterns.link_dest_1.match(text, i)
    if m:
        link_dest = m.start(), m.end(), m.group()
        i = m.end()
    else:
        open_num = 0
        escaped = False
        prev = i
        while i < len(text):
            c = text[i]
            if escaped:
                escaped = False
            elif c == '\\':
                escaped = True
            elif c == '(':
                open_num += 1
            elif c in string.whitespace:
                break
            elif c == ')':
                if open_num > 0:
                    open_num -= 1
                else:
                    break
            i += 1
        if open_num != 0:
            return None
        link_dest = prev, i, text[prev:i]
    link_title = i, i, None
    tail_re = re.compile(r'(?:\s+%s)?\s*\)' % patterns.link_title, flags=re.UNICODE)
    m = tail_re.match(text, i)
    if not m:
        return None
    if m.group('title'):
        link_title = m.start('title'), m.end('title'), m.group('title')
    return (link_dest, link_title, m.end())
1184997
public Regex then(Regex regex) {
      if (regex == null) {
         return this;
      }
      return re(this.pattern + regex.pattern);
   }
133356
def find_previous_word_beginning(self, count=1, WORD=False):
        
        if count < 0:
            return self.find_next_word_beginning(count=-count, WORD=WORD)

        regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE
        iterator = regex.finditer(self.text_before_cursor[::-1])

        try:
            for i, match in enumerate(iterator):
                if i + 1 == count:
                    return - match.end(1)
        except StopIteration:
            pass
1202224
def _starts_with_regex(line, regex):
    """"""
    if not regex.startswith('^'):
        regex = '^' + regex
    reg = re.compile(regex)
    return reg.match(line)
248295
function pattern(toMatch) {
  var regexps = getQMarkPaths(toMatch, [])

  //reassign array to compiled regular expressions
  regexps.forEach(function(aPath, ix) {
    regexps[ix] = compile(aPath, true).regexp //'true' tells regexp compiler to math till end => '$'
  })


  if (regexps.length === 1) { //fast case
    var reg = regexps[0]
    return reg.test.bind(reg)
  } else { //test each potential path
    return function (testAgainst) {
      for (var i = 0; i < regexps.length; i++) {
        if (regexps[i].test(testAgainst)) return true
      }

      return false
    }
  }
}
943470
def next_line(self, require_prefix=True):
        
        if require_prefix:
            m = self.expect_re(r'(?m)[^\n]*?$\n?')
        else:
            m = self._expect_re(r'(?m)[^\n]*$\n?', self.pos)
        self.match = m
        if m:
            return m.group()
1153046
function (regexp) {
        var res = maybeCallNative(nativeSearch, regexp, this);
        if (res.done) return res.value;

        var rx = anObject(regexp);
        var S = String(this);

        var previousLastIndex = rx.lastIndex;
        if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
        var result = regExpExec(rx, S);
        if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex;
        return result === null ? -1 : result.index;
      }
1173341
private boolean matchRegexp(String s, Pattern pattern) {
    final Matcher m = pattern.matcher(s);
    return m.matches();
  }
1341021
def _find_prev regex=@last_regex, start = @search_found_ix, first_time = false
      #TODO the firsttime part, see find_next
      #raise "No previous search" if regex.nil?
      warn "No previous search" and return if regex.nil?
      #$log.debug " _find_prev #{@search_found_ix} : #{@current_index}"
      if start != 0
        start -= 1 unless start == 0
        @last_regex = regex
        @search_start_ix = start
        regex = Regexp.new(regex, Regexp::IGNORECASE) if @search_case
        start.downto(0) do |ix| 
          row = @list[ix].to_s
          m=row.match(regex)
          if !m.nil?
            @find_offset = m.offset(0)[0]
            @find_offset1 = m.offset(0)[1]
            ix += (@_header_adjustment || 0)
            @search_found_ix = ix
            return ix 
          end
        end
      end
      fend = start-1
      start = @list.size-1
      if @search_wrap
        start.downto(fend) do |ix| 
          row = @list[ix].to_s
          m=row.match(regex)
          if !m.nil?
            @find_offset = m.offset(0)[0]
            @find_offset1 = m.offset(0)[1]
            ix += (@_header_adjustment || 0)
            @search_found_ix = ix
            return ix 
          end
        end
      end
      return nil
    end
940215
def substitute_timestep(self, regex, timestep):
        

        # Make one change at a time, each change affects subsequent matches.
        timestep_changed = False
        while True:
            matches = re.finditer(regex, self.str, re.MULTILINE | re.DOTALL)
            none_updated = True
            for m in matches:
                if m.group(1) == timestep:
                    continue
                else:
                    self.str = (self.str[:m.start(1)] + timestep +
                                self.str[m.end(1):])
                    none_updated = False
                    timestep_changed = True
                    break

            if none_updated:
                break

        if not timestep_changed:
            sys.stderr.write('WARNING: no update with {0}.\n'.format(regex))