Parse a regular expression. Some context-awareness is necessary, since a '/' inside a '[]' set does not end the expression.
5538
function tryCreateRegexp(src, flags, throwErrorAt, parser) {
  try {
    return new RegExp(src, flags);
  } catch (e) {
    if (throwErrorAt !== undefined) {
      if (e instanceof SyntaxError) parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message);
      throw e;
    }
  }
}
184336
function parse()
    {
        $criteria        = $this->criteria;
        $expectAsLiteral = $this->expectAsLiteral;


        $TOKENS  = preg_quote(static::TOKENS);

        $expectAsLiteral = (empty($expectAsLiteral)) ? '/@+-.' : $expectAsLiteral;
        $LITERAL = preg_quote($expectAsLiteral).'A-Za-z0-9_';


        $currentPos = 0;
        $length     = strlen($criteria);
        $parts      = [];
        $levelParts = [&$parts];
        $level      = 0;

        while ($currentPos < $length)
        {
            preg_match("(\G(?P<_literal_>[$LITERAL]*)(?P<_token_>[$TOKENS]|$))"
                , $criteria
                , $matches
                , 0
                , $currentPos
            );

            if ( empty($matches) )
                break;

            if (! empty($matches['_literal_']) ) {
                $levelParts[$level][] = ['_literal_' => $matches['_literal_']];
                $currentPos += strlen($matches['_literal_']);
            }

            # Deal With Token:
            if ( !isset($matches['_token_']) || $matches['_token_'] == '' )
                continue;

            $currentPos += strlen($matches['_token_']);
            $Token = $matches['_token_'];

            ## Regular Expression Token
            #
            #
            if ($Token === '~') {
                // ^ match any character that is not in list
                $pmatch = preg_match("/~(?P<_delimiter_>[^~]+)~/"
                    , $criteria
                    , $matches
                    , 0
                    , 0
                );
                if (! $pmatch )
                    throw new \RuntimeException('Miss usage of ~ ~ token.');

                $val['_regex_'] = $matches['_delimiter_'];
                $levelParts[$level][] = $val;

                $currentPos += strlen($matches[0])+2/*~x~*/;
            }
            ##
            # Variable
            # /:hash_id~\w{24}~
            #
            elseif ($Token === ':') {
                // ^$TOKENS  match any character that is not in list
                $pmatch = preg_match("(\G(?P<_name_>[^$TOKENS]+)(?:~(?P<_delimiter_>[^~]+)~)?:?)"
                    , $criteria
                    , $matches
                    , 0
                    , $currentPos
                );

                if (! $pmatch && !(isset($matches['_name_']) && isset($matches['_delimiter_'])) )
                    throw new \RuntimeException(
                        'Found empty parameter name or delimiter on (%s).'
                        , $criteria
                    );

                $parameter = $matches['_name_'];
                $val       = ['_parameter_' => $parameter];
                if (isset($matches['_delimiter_']))
                    $val[$parameter] = $matches['_delimiter_'];

                $levelParts[$level][] = $val;
                $currentPos += strlen($matches[0]);
            }

            ## Literal Token
            #  localhost\:port
            #
            elseif ($Token === '\\') {
                // Consider next character as Literal
                $nextChar = $currentPos += 1;
                $levelParts[$level][]   = ['_literal_' => $criteria[$nextChar]];
            }

            ## Optional Part
            #  /<u/:username~[a-zA-Z0-9._]+~><-:userid~\w{24}~>
            #
            elseif ($Token === '<') {
                if (! isset($va) ) {
                    $va = [];
                    $n = 0;
                }

                $n++;
                $va[$n] = [];
                $levelParts[$level][] = ['_optional_' => &$va[$n]];
                $level++;
                $levelParts[$level] = &$va[$n];
            }
            ## Close Optional ##
            elseif ($Token === '>') {
                unset($levelParts[$level]);
                $level--;

                if ($level < 0)
                    throw new \RuntimeException('Found closing bracket without matching opening bracket');
            }

            else
                // Recognized unused token return immanently
                $levelParts[$level][]   = ['_token_' => $Token];

        } // end while

        if ($level > 0)
            throw new \RuntimeException('Found unbalanced brackets');


        return ParsedCriteria::of($parts);
    }
363476
function parse(str) {

  // find the prefix expressions and the main value
  var stringMatches = str.match(stringRegex)
  var allExpString = stringMatches[1] || ''
  var value = stringMatches[2]

  // parse each prefix expression
  var expressions = execAll(allExpressionsRegex, allExpString)
    // grab the expression content inside the braces
    .map(function (match) { return match[1] })
    .map(parseExpression)

  return {
    original:   str,
    value:      value,
    expressions: expressions
  }
}
646740
def parse(self, string, parent):
        """"""
        result = {}
        for member in self.RE_MEMBERS.finditer(string):
            mems = self._process_member(member, parent, string)
            #The regex match could contain multiple members that were defined
            #on the same line in the code file.
            for onemem in mems:
                result[onemem.name.lower()] = onemem
                
        return result
742802
function parseRegExp( str ) {
	var re = regex( str );
	if ( re === null ) {
		return new TypeError( 'invalid value. Unable to parse string as a regular expression. Value: `' + str + '`.' );
	}
	return re;
}
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')
135285
public boolean isNextIn(Context context) {
        return regex == null || regex.matcher(context.getSource().subToEnd()).lookingAt();
    }
1302431
def parse(self, text):
        
        #: Do not process empty strings (Issue #3)
        if text.strip() == "":
            return ""
        #: Do not process strings consisting of a single punctuation mark (Issue #4)
        elif text.strip() in PUNCTUATION:
            _sym = text.strip()
            if _sym in tuple('.?!'):
                _tag = "."
            else:
                _tag = _sym
            if self.lemmata:
                return "{0}/{1}/O/O/{0}".format(_sym, _tag)
            else:
                return "{0}/{1}/O/O".format(_sym, _tag)
        if self.tokenize:
            _tokenized = " ".join(self.tokenizer.tokenize(text))
        else:
            _tokenized = text

        _parsed = pattern_parse(_tokenized,
                                # text is tokenized before it is passed on to
                                # pattern.de.parse
                                tokenize=False,
                                tags=self.tags, chunks=self.chunks,
                                relations=self.relations, lemmata=self.lemmata,
                                encoding=self.encoding, tagset=self.tagset)
        if self.pprint:
            _parsed = pattern_pprint(_parsed)

        return _parsed
536295
function parseRegExp (str) {
  if (str instanceof RegExp) return str
  let arg = String(str).match(/^\/(.*)\/(g|i|)$|.*/)
  return new RegExp(arg[1] || arg[0], arg[2])
}
746852
def parse_expression(source: str) -> ExpressionSource:
    ''''''
    if not is_expression(source):
        msg = 'Expression is not valid. Expression should be matched with regular expression: {0}'\
              .format(EXPRESSION_REGEX)
        raise ExpressionError(msg, source)
    if not source.startswith('{'):
        [type_, source] = source.split(':', 1)
    elif source.endswith('}}'):
        type_ = 'twoways'
    else:
        type_ = 'oneway'
    return (type_, source[1:-1])
97190
def parse_set(string):
    """"""
    string = string.strip()
    if string:
        return set(string.split(","))
    else:
        return set()
1214640
@GwtIncompatible("java.util.regex.Pattern")
  public void matches(Pattern regex) {
    if (!regex.matcher(actual()).matches()) {
      failWithActual("expected to match", regex);
    }
  }
365509
function parse(str) {

    let res = {};

    str.split(constants.REGEX.newline).map(line => {

        line = line.trim();

        // ignore empty lines and comments
        if (!line || line[0] === '#') {
            return;
        }

        // replace variables that are not escaped
        line = line.replace(constants.REGEX.args, (match, $1, $2) => {

            let key = $1 !== undefined ? $1 : $2;

            if (match.slice(0, 2) === '\\\\') {
                return match.slice(2);
            }

            return process.env[key] !== undefined ? process.env[key] : res[key];

        });

        // find the line split index based on the first occurence of = sign
        let index = line.indexOf('=') > -1 ? line.indexOf('=') : line.length;

        // get key/val and trim whitespace
        let key = line.slice(0, index).trim();
        let val = line.slice(index +1).trim();

        val = parseComment(val).replace(constants.REGEX.quotes, '');

        res[key] = unescape(val);

    });

    return res;

}
1208202
function parsePattern(pattern) {
	var regexSpecialChars = /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g;
	// Treat consecutive wildcards as one (#12)
	var wildCardPattern = /\*+/g;
	var endOfLinePattern = /\\\$$/;

	pattern = normaliseEncoding(pattern)

	if (pattern.indexOf('*') < 0 && pattern.indexOf('$') < 0) {
		return pattern;
	}

	pattern = pattern
		.replace(regexSpecialChars, '\\$&')
		.replace(wildCardPattern, '(?:.*)')
		.replace(endOfLinePattern, '$');

	return new RegExp(pattern);
}
687378
def p_regex_literal(self, p):
        """"""
        p[0] = self.asttypes.Regex(p[1])
        p[0].setpos(p)
911165
public static boolean regexMatch(String input, String regex) {
        return Pattern.compile(regex).matcher(input).matches();
    }
652106
def parse_charset(charset):
    
    import re
    regex = r'(\w-\w)'
    pat = re.compile(regex)
    found = pat.findall(charset)
    result = ''
    if found:
        for element in found:
            for char in char_range(element[0], element[-1]):
                result += char
        return result
    return charset