Turn all capturing groups in a regular expression pattern into
        non-capturing groups.
185730
def _re_flatten(p):
    '''  '''
    if '(' not in p: return p
    return re.sub(r'(\\*)(\(\?P<[^>]+>|\((?!\?))',
        lambda m: m.group(0) if len(m.group(1)) % 2 else m.group(1) + '(?:', p)
484669
function regexpToRegexp(regex, keys, options) {
  if (!Array.isArray(keys)) return regex.source;

  let groups = regex.source.match(/\((?!\?)/g);
  if (!groups) return regex.source;

  let i = 0;
  let group = () => ({
    name: i++,
    prefix: null,
    delimiter: null,
    optional: false,
    repeat: false,
    partial: false,
    pattern: null
  });

  groups.forEach(() => keys.push(group()));
  return regex.source;
}
1219585
def match_subgroup(sequence, pattern):
    """"""

    for element in sequence:
        match = re.match(pattern, element)

        if match:
            yield match.groupdict()
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);
}
598125
def capture(self, pattern, name=None):
        

        if isinstance(pattern, basestring):
            pattern = re.compile(pattern)

        def munge(self, value):
            match = pattern.match(value)
            if not match:
                return NONE
            for group in [name or self.name, 1]:
                try:
                    return match.group(group)
                except IndexError:
                    pass
            return NONE

        return self.munge.attach(self)(munge)
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
1354571
def tokenize(string):
    """"""
    for match in TOKENS_REGEX.finditer(string):
        yield Token(match.lastgroup, match.group().strip(), match.span())
1065304
def tokenize(text, format=None):
    
    text = Text(text)
    text = text.replace("\t", " ")
    tokens = re.findall(patterns, text)
    tokens = [token[0] for token in tokens]
    if format == "text":
        return " ".join(tokens)
    else:
        return tokens
315970
def nonalpha_split(string):
    ''''''
    return re.findall(r'[%s]+|[^%s]+' % (A, A), string, flags=FLAGS)
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 "";
    }
704658
def _regex_from_encoded_pattern(s):
    """'
    """
    if s.startswith('/') and s.rfind('/') != 0:
        # Parse it: /PATTERN/FLAGS
        idx = s.rfind('/')
        pattern, flags_str = s[1:idx], s[idx+1:]
        flag_from_char = {
            "i": re.IGNORECASE,
            "l": re.LOCALE,
            "s": re.DOTALL,
            "m": re.MULTILINE,
            "u": re.UNICODE,
        }
        flags = 0
        for char in flags_str:
            try:
                flags |= flag_from_char[char]
            except KeyError:
                raise ValueError("unsupported regex flag: '%s' in '%s' "
                                 "(must be one of '%s')"
                                 % (char, s, ''.join(list(flag_from_char.keys()))))
        return re.compile(s[1:idx], flags)
    else: # not an encoded regex
        return re.compile(re.escape(s))
657222
def strip_between(self, string, start, end):
        """"""
        regex = start + r'.*?' + end + r'\s*'
        res = re.sub(regex, '', string,
                     flags=re.DOTALL|re.IGNORECASE|re.MULTILINE)
        return res
6093
function normalize(pattern) {
        var type = toString.call(pattern);
        switch (type) {
            case '[object String]':
                return _.glob(pattern);
            case '[object RegExp]':
                return pattern;
            default:
                xgulp.log.error('invalid regexp [%s].', pattern);
        }
    }
1156889
public static String extractRegexGroup(String fromContent, String regex) throws Exception {
        return extractRegexGroup(fromContent, regex, 1);
    }
44129
def split(self, sep=None, maxsplit=None, regex=False):
        """"""
        if maxsplit is not None:
            raise NotImplementedError('no maxsplit yet')
        s = self.s
        if sep is None:
            sep = r'\s+'
        elif not regex:
            sep = re.escape(sep)
        matches = list(re.finditer(sep, s))
        return [self[start:end] for start, end in zip(
            [0] + [m.end() for m in matches],
            [m.start() for m in matches] + [len(s)])]
1002066
def normalize_pattern(pattern):
    
    if not (pattern.startswith('RE:') or pattern.startswith('!RE:')):
        pattern = _slashes.sub('/', pattern)
    if len(pattern) > 1:
        pattern = pattern.rstrip('/')
    return pattern
1335326
def _construct_regex(cls, fmt):
        """"""
        return re.compile(fmt.format(**vars(cls)), flags=re.U)