Find group in each string in the Series using passed regular expression.

    :param expr:
    :param pat: Pattern or regular expression
    :param flags: re module, e.g. re.IGNORECASE
    :param group: if None as group 0
    :return: sequence or scalar
770017
def _extract(expr, pat, flags=0, group=0):
    

    return _string_op(expr, Extract, _pat=pat, _flags=flags, _group=group)
691570
def get_regex(self):
        '''  '''
        regex = ''
        for flag in self.compound:
            if flag == '?' or flag == '*':
                regex += flag
            else:
                regex += '(' + '|'.join(self.flags[flag]) + ')'

        return regex
493951
function PatternGroup(patterns) {

    this._pattern = l.map(patterns, function(expr) {
        return Pattern.toPattern(expr);
    });

}
19279
def regex_search(txt, rgx, ignorecase=False, multiline=False):
    '''
    
    '''
    flag = 0
    if ignorecase:
        flag |= re.I
    if multiline:
        flag |= re.M
    obj = re.search(rgx, txt, flag)
    if not obj:
        return
    return obj.groups()
1156889
public static String extractRegexGroup(String fromContent, String regex) throws Exception {
        return extractRegexGroup(fromContent, regex, 1);
    }
790691
def pattern_match(pattern, string):
    
    def backtrack(pattern, string, dic):

        if len(pattern) == 0 and len(string) > 0:
            return False

        if len(pattern) == len(string) == 0:
            return True

        for end in range(1, len(string)-len(pattern)+2):
            if pattern[0] not in dic and string[:end] not in dic.values():
                dic[pattern[0]] = string[:end]
                if backtrack(pattern[1:], string[end:], dic):
                    return True
                del dic[pattern[0]]
            elif pattern[0] in dic and dic[pattern[0]] == string[:end]:
                if backtrack(pattern[1:], string[end:], dic):
                    return True
        return False

    return backtrack(pattern, string, {})
1090989
def search(self, regex, flags=0):
        
        return self._generate_test(
            lambda value: re.search(regex, value, flags),
            ('search', self._path, regex)
        )
193756
def get_group_value(self, token, match):
        """"""
        try:
            value = match.group('{}_{}'.format(token.name, self.group))
        except IndexError:
            value = ''
        return self.func(value) if callable(self.func) else value
1224767
def p_scalar_group(self, p):
        
        if len(p) == 2:
            p[0] = (str(p[1]),)

        if len(p) == 3:
            p[0] = p[1] + (str(p[2]),)

        if len(p) == 4:
            p[0] = p[1] + (str(p[3]),)
573628
def p_exprlt(p):
    
    a = int(p[1]) if p[1].isdigit() else 0
    b = int(p[3]) if p[3].isdigit() else 0

    p[0] = '1' if a < b else '0'
173905
def parse_regex(regex_tokens):
    
    # We add a closing brace because that represents the final pop of the stack.
    tokens = [')'] + regex_tokens[::-1]

    def wrap(lst):
        """ Turn list into sequence when it contains several items. """
        if len(lst) == 1:
            return lst[0]
        else:
            return Sequence(lst)

    def _parse():
        or_list = []
        result = []

        def wrapped_result():
            if or_list == []:
                return wrap(result)
            else:
                or_list.append(result)
                return Any([wrap(i) for i in or_list])

        while tokens:
            t = tokens.pop()

            if t.startswith('(?P<'):
                variable = Variable(_parse(), varname=t[4:-1])
                result.append(variable)

            elif t in ('*', '*?'):
                greedy = (t == '*')
                result[-1] = Repeat(result[-1], greedy=greedy)

            elif t in ('+', '+?'):
                greedy = (t == '+')
                result[-1] = Repeat(result[-1], min_repeat=1, greedy=greedy)

            elif t in ('?', '??'):
                if result == []:
                    raise Exception('Nothing to repeat.' + repr(tokens))
                else:
                    greedy = (t == '?')
                    result[-1] = Repeat(result[-1], min_repeat=0, max_repeat=1, greedy=greedy)

            elif t == '|':
                or_list.append(result)
                result = []

            elif t in ('(', '(?:'):
                result.append(_parse())

            elif t == '(?!':
                result.append(Lookahead(_parse(), negative=True))

            elif t == '(?=':
                result.append(Lookahead(_parse(), negative=False))

            elif t == ')':
                return wrapped_result()

            elif t.startswith('#'):
                pass

            elif t.startswith('{'):
                # TODO: implement!
                raise Exception('{}-style repitition not yet supported' % t)

            elif t.startswith('(?'):
                raise Exception('%r not supported' % t)

            elif t.isspace():
                pass
            else:
                result.append(Regex(t))

        raise Exception("Expecting ')' token")

    result = _parse()

    if len(tokens) != 0:
        raise Exception("Unmatched parantheses.")
    else:
        return result
341016
def matchiter(r, s, flags=0):
    
    if isinstance(r, basestring):
        r = re.compile(r, flags)
    i = 0
    while s:
        m = r.match(s)
        g = m and m.group(0)
        if not m or not g:
            raise ValueError("{}: {!r}".format(i, s[:50]))
        i += len(g)
        s = s[len(g):]
        yield m
382799
def warnExtractFromRegexpGroups(self, line, match):
        
        file = match.group(1)
        lineNo = match.group(2)
        if lineNo is not None:
            lineNo = int(lineNo)
        text = match.group(3)
        return (file, lineNo, text)
133036
def _startswith(expr, pat):
    

    return _string_op(expr, Startswith, output_type=types.boolean, _pat=pat)
1174014
function regexpFlags(regexp) {
  let flags = regexp.flags
  if (flags === undefined) {
    flags = ''
    if (regexp.ignoreCase) flags += 'i'
    if (regexp.global) flags += 'g'
    if (regexp.multiline) flags += 'm'
  }
  return flags
}
500172
def _regex_span(_regex, _str, case_insensitive=True):
    
    if case_insensitive:
        flags = regex.IGNORECASE | regex.FULLCASE | regex.VERSION1
    else:
        flags = regex.VERSION1
    comp = regex.compile(_regex, flags=flags)
    matches = comp.finditer(_str)
    for match in matches:
        yield match
675381
public static String extractRegexGroup(String fromContent, Pattern regex, int groupNumber) throws Exception {
        if (fromContent == null) {
            throw new Exception("Cannot extract regex group because the provided content string is null.");
        }
        if (regex == null) {
            throw new Exception("Cannot extract regex group because the provided regular expression is null.");
        }
        if (groupNumber < 0) {
            throw new Exception("Group number to extract must be non-negative. Provided group number was " + groupNumber);
        }
        Matcher matcher = regex.matcher(fromContent);
        if (!matcher.find()) {
            throw new Exception("Did not find any matches for regex [" + regex + "] in the provided content: [" + fromContent + "].");
        }
        if (matcher.groupCount() < groupNumber) {
            throw new Exception("Found " + matcher.groupCount() + " matching groups in the content, but expected at least " + groupNumber + ". Regex was [" + regex + "] and content was [" + fromContent + "].");
        }
        return matcher.group(groupNumber);
    }