function UrlMatcher(pattern, config, parentMatcher) {
  config = extend({ params: {} }, isObject(config) ? config : {});

  // Find all placeholders and create a compiled pattern, using either classic or curly syntax:
  //   '*' name
  //   ':' name
  //   '{' name '}'
  //   '{' name ':' regexp '}'
  // The regular expression is somewhat complicated due to the need to allow curly braces
  // inside the regular expression. The placeholder regexp breaks down as follows:
  //    ([:*])([\w\[\]]+)              - classic placeholder ($1 / $2) (search version has - for snake-case)
  //    \{([\w\[\]]+)(?:\:( ... ))?\}  - curly brace placeholder ($3) with optional regexp/type ... ($4) (search version has - for snake-case
  //    (?: ... | ... | ... )+         - the regexp consists of any number of atoms, an atom being either
  //    [^{}\\]+                       - anything other than curly braces or backslash
  //    \\.                            - a backslash escape
  //    \{(?:[^{}\\]+|\\.)*\}          - a matched set of curly braces containing other atoms
  var placeholder       = /([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,
      searchPlaceholder = /([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,
      compiled = '^', last = 0, m,
      segments = this.segments = [],
      parentParams = parentMatcher ? parentMatcher.params : {},
      params = this.params = parentMatcher ? parentMatcher.params.$$new() : new $$UMFP.ParamSet(),
      paramNames = [];

  function addParameter(id, type, config, location) {
    paramNames.push(id);
    if (parentParams[id]) return parentParams[id];
    if (!/^\w+(-+\w+)*(?:\[\])?$/.test(id)) throw new Error("Invalid parameter name '" + id + "' in pattern '" + pattern + "'");
    if (params[id]) throw new Error("Duplicate parameter name '" + id + "' in pattern '" + pattern + "'");
    params[id] = new $$UMFP.Param(id, type, config, location);
    return params[id];
  }

  function quoteRegExp(string, pattern, squash) {
    var surroundPattern = ['',''], result = string.replace(/[\\\[\]\^$*+?.()|{}]/g, "\\$&");
    if (!pattern) return result;
    switch(squash) {
      case false: surroundPattern = ['(', ')'];   break;
      case true:  surroundPattern = ['?(', ')?']; break;
      default:    surroundPattern = ['(' + squash + "|", ')?'];  break;
    }
    return result + surroundPattern[0] + pattern + surroundPattern[1];
  }

  this.source = pattern;

  // Split into static segments separated by path parameter placeholders.
  // The number of segments is always 1 more than the number of parameters.
  function matchDetails(m, isSearch) {
    var id, regexp, segment, type, cfg, arrayMode;
    id          = m[2] || m[3]; // IE[78] returns '' for unmatched groups instead of null
    cfg         = config.params[id];
    segment     = pattern.substring(last, m.index);
    regexp      = isSearch ? m[4] : m[4] || (m[1] == '*' ? '.*' : null);
    type        = $$UMFP.type(regexp || "string") || inherit($$UMFP.type("string"), { pattern: new RegExp(regexp) });
    return {
      id: id, regexp: regexp, segment: segment, type: type, cfg: cfg
    };
  }

  var p, param, segment;
  while ((m = placeholder.exec(pattern))) {
    p = matchDetails(m, false);
    if (p.segment.indexOf('?') >= 0) break; // we're into the search part

    param = addParameter(p.id, p.type, p.cfg, "path");
    compiled += quoteRegExp(p.segment, param.type.pattern.source, param.squash);
    segments.push(p.segment);
    last = placeholder.lastIndex;
  }
  segment = pattern.substring(last);

  // Find any search parameter names and remove them from the last segment
  var i = segment.indexOf('?');

  if (i >= 0) {
    var search = this.sourceSearch = segment.substring(i);
    segment = segment.substring(0, i);
    this.sourcePath = pattern.substring(0, last + i);

    if (search.length > 0) {
      last = 0;
      while ((m = searchPlaceholder.exec(search))) {
        p = matchDetails(m, true);
        param = addParameter(p.id, p.type, p.cfg, "search");
        last = placeholder.lastIndex;
        // check if ?&
      }
    }
  } else {
    this.sourcePath = pattern;
    this.sourceSearch = '';
  }

  compiled += quoteRegExp(segment) + (config.strict === false ? '\/?' : '') + '$';
  segments.push(segment);

  this.regexp = new RegExp(compiled, config.caseInsensitive ? 'i' : undefined);
  this.prefix = segments[0];
  this.$$paramNames = paramNames;
}
@ngdoc object
@name ui.router.util.type:UrlMatcher

@description
Matches URLs against patterns and extracts named parameters from the path or the search
part of the URL. A URL pattern consists of a path pattern, optionally followed by '?' and a list
of search parameters. Multiple search parameter names are separated by '&'. Search parameters
do not influence whether or not a URL is matched, but their values are passed through into
the matched parameters returned by {@link ui.router.util.type:UrlMatcher#methods_exec exec}.

Path parameter placeholders can be specified using simple colon/catch-all syntax or curly brace
syntax, which optionally allows a regular expression for the parameter to be specified:

* `':'` name - colon placeholder
* `'*'` name - catch-all placeholder
* `'{' name '}'` - curly placeholder
* `'{' name ':' regexp|type '}'` - curly placeholder with regexp or type name. Should the
  regexp itself contain curly braces, they must be in matched pairs or escaped with a backslash.

Parameter names may contain only word characters (latin letters, digits, and underscore) and
must be unique within the pattern (across both path and search parameters). For colon 
placeholders or curly placeholders without an explicit regexp, a path parameter matches any
number of characters other than '/'. For catch-all placeholders the path parameter matches
any number of characters.

Examples:

* `'/hello/'` - Matches only if the path is exactly '/hello/'. There is no special treatment for
  trailing slashes, and patterns have to match the entire path, not just a prefix.
* `'/user/:id'` - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or
  '/user/bob/details'. The second path segment will be captured as the parameter 'id'.
* `'/user/{id}'` - Same as the previous example, but using curly brace syntax.
* `'/user/{id:[^/]*}'` - Same as the previous example.
* `'/user/{id:[0-9a-fA-F]{1,8}}'` - Similar to the previous example, but only matches if the id
  parameter consists of 1 to 8 hex digits.
* `'/files/{path:.*}'` - Matches any URL starting with '/files/' and captures the rest of the
  path into the parameter 'path'.
* `'/files/*path'` - ditto.
* `'/calendar/{start:date}'` - Matches "/calendar/2014-11-12" (because the pattern defined
  in the built-in  `date` Type matches `2014-11-12`) and provides a Date object in $stateParams.start

@param {string} pattern  The pattern to compile into a matcher.
@param {Object} config  A configuration object hash:
@param {Object=} parentMatcher Used to concatenate the pattern/config onto
  an existing UrlMatcher

* `caseInsensitive` - `true` if URL matching should be case insensitive, otherwise `false`, the default value (for backward compatibility) is `false`.
* `strict` - `false` if matching against a URL with a trailing slash should be treated as equivalent to a URL without a trailing slash, the default value is `true`.

@property {string} prefix  A static prefix of this pattern. The matcher guarantees that any
  URL matching this matcher (i.e. any string for which {@link ui.router.util.type:UrlMatcher#methods_exec exec()} returns
  non-null) will start with this prefix.

@property {string} source  The pattern that was passed into the constructor

@property {string} sourcePath  The path portion of the source property

@property {string} sourceSearch  The search portion of the source property

@property {string} regex  The constructed regex that will be used to match against the url when 
  it is time to determine which url will match.

@returns {Object}  New `UrlMatcher` object