Will take a path like 'element[0][1].subElement["Hey!.What?"]["[hey]"]' and return ["element", "0", "1", "subElement", "Hey!.What?", "[hey]"]
434697
function keysFromPath(path) {
    // from http://codereview.stackexchange.com/a/63010/8176
    /**
     * Repeatedly capture either:
     * - a bracketed expression, discarding optional matching quotes inside, or
     * - an unbracketed expression, delimited by a dot or a bracket.
     */
    var re = /\[("|')(.+)\1\]|([^.\[\]]+)/g;

    var elements = [];
    var result;
    while ((result = re.exec(path)) !== null) {
      elements.push(result[2] || result[3]);
    }
    return elements;
  }
321002
function () {
    var startPos = scanner.pos;
    var result;
    if ((result = BlazeTools.parseNumber(scanner))) {
      return ['NUMBER', result.value];
    } else if ((result = BlazeTools.parseStringLiteral(scanner))) {
      return ['STRING', result.value];
    } else if (/^[\.\[]/.test(scanner.peek())) {
      return ['PATH', scanPath()];
    } else if (run(/^\(/)) {
      return ['EXPR', scanExpr('EXPR')];
    } else if ((result = BlazeTools.parseExtendedIdentifierName(scanner))) {
      var id = result;
      if (id === 'null') {
        return ['NULL', null];
      } else if (id === 'true' || id === 'false') {
        return ['BOOLEAN', id === 'true'];
      } else {
        scanner.pos = startPos; // unconsume `id`
        return ['PATH', scanPath()];
      }
    } else {
      expected('identifier, number, string, boolean, null, or a sub expression enclosed in "(", ")"');
    }
  }
212071
private function translatePathElement($path, &$paramsRef)
    {
        $dotPos   = strpos($path, '.');
        $currPath = $path;
        if($dotPos !== false)
        {
            $currPath = substr($path, 0, $dotPos);
        }

        if($currPath == '*')
        {
            //Hell begins
            if($dotPos !== false)
            {
                //create a new copy and merge everything from one level up
                $newParamsRef = array();
                foreach ($paramsRef as $subArray) {
                    if(is_array($subArray))
                    {
                        foreach ($subArray as $key => $value) {
                            if(isset($newParamsRef[$key]))
                            {
                                $newParamsRef[$key][] = $value;
                            }
                            else
                            {
                                if(is_array($value))
                                {
                                    $newParamsRef[$key] = $value;
                                }
                                else
                                {
                                    $newParamsRef[$key] = array($value);
                                }
                            }
                        }
                    }
                }
                return $this->translatePathElement(substr($path, $dotPos + 1), $newParamsRef);
            }
            else
            {
                return $paramsRef;
            }
        }
        if(($lbracktePos = strpos($currPath, '[')) !== false)
        {
            $subPath = substr($currPath, 0, $lbracktePos);
            $index   = intval(substr($currPath, $lbracktePos+1, -1));

            if(isset($paramsRef[$subPath]) && is_array($paramsRef[$subPath]) && isset($paramsRef[$subPath][$index]))
            {
                if($dotPos === false)
                {
                    return $paramsRef[$subPath][$index];
                }
                else
                {
                    return $this->translatePathElement(substr($path, $dotPos + 1), $paramsRef[$subPath][$index]);
                }
            }
        }
        else
        {
            if(isset($paramsRef[$currPath]))
            {
                if($dotPos === false)
                {
                    return $paramsRef[$currPath];
                }
                else
                {
                    return $this->translatePathElement(substr($path, $dotPos + 1), $paramsRef[$currPath]);
                }
            }
        }

        return null;
    }
776297
def NormalizeRelativePath(path):
        """"""
        path_components = path.split('/')
        normalized_components = []
        for component in path_components:
            if re.match(r'{[A-Za-z0-9_]+}$', component):
                normalized_components.append(
                    '{%s}' % Names.CleanName(component[1:-1]))
            else:
                normalized_components.append(component)
        return '/'.join(normalized_components)
654576
public static String pathElement(final int index,
                                   final String path) {
    final String[] paths = path.split("/");

    int idx = index;

    if ((paths[0] == null) || (paths[0].length() == 0)) {
      // skip empty first part - leading "/"
      idx++;
    }

    if (idx >= paths.length) {
      return null;
    }

    return paths[idx];
  }
921265
private static void getResPathKeys(String path, int num, String[] keys, int start) {
        if (num == 0) {
            return;
        }
        if (num == 1) {
            keys[start] = path;
            return;
        }
        int i = 0;
        for (;;) {
            int j = path.indexOf(RES_PATH_SEP_CHAR, i);
            assert j >= i;
            keys[start++] = path.substring(i, j);
            if (num == 2) {
                assert path.indexOf(RES_PATH_SEP_CHAR, j + 1) < 0;
                keys[start] = path.substring(j + 1);
                break;
            } else {
                i = j + 1;
                --num;
            }
        }
    }
220912
function getPathArray(path) {
    var pathArray = [];
    path.replace(rePropName, function(match, number, quote, string) {
        pathArray.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
    });
    return pathArray;
}
394620
function split(path) {
    var res = [];
    var level = 0;
    var key = '';

    for (var i = 0; i < path.length; i++) {
      var c = path.substr(i, 1);

      if (level === 0 && (c === '.' || c === '[')) {
        if (c === '[') {
          level++;
          i++;
          c = path.substr(i, 1);
        }

        if (key) { // the first value could be a string
          res.push(key);
        }
        key = '';
        continue;
      }

      if (c === ']') {
        level--;
        key = key.slice(0, -1);
        continue;
      }

      key += c;
    }

    res.push(key);

    return res;
  }
1001786
function (pathParts) {
            var path = [pathParts[0]];
            for (var index = 1, len = pathParts.length; index < len; index++) {
                path.push("[\"" + ("" + pathParts[index]).replace(/"/gi, '\\"') + "\"]");
            }
            return path.join('');
        }
575328
function parseSliceString(path, l) {
  var _path$split$map = path.split(':').map(function (s) {
    return parseNumber(s);
  }),
      _path$split$map2 = _slicedToArray(_path$split$map, 3),
      start = _path$split$map2[0],
      end = _path$split$map2[1],
      step = _path$split$map2[2];
  // 异常的时候默认值


  start = isNaN(start) ? 0 : start < 0 ? l + start : start;

  end = isNaN(end) ? l : end < 0 ? l + end : // 小于 0 转成正数
  end > l ? l : end; // 最大为长度

  step = isNaN(step) ? 1 : step;

  invariant(step !== 0, 'Step can not be zero!');

  return [start, end, step];
}
62245
def rec_split_path(path):
    ''''''
    if len(path) > 1 and path.endswith('/'):
        path = path[:-1]
    if '/' not in path:
        return [path,]
    result = []
    while path != '/':
        parent, name = os.path.split(path)
        result.append((path, name))
        path = parent
    result.append(('/', '/'))
    result.reverse()
    return result
605793
function getPathParts(path) {
  // split the path specified into an array on `.`
  const pathParts = String(path).split('.');

  // create an empty array which will be the result
  const parts = [];

  // create an index variable so we can skip indexes if
  // need be when parsing the paths
  let index = 0;

  // while the index is smaller then the parts array length
  while (index < pathParts.length) {
    // get the part from the parts array
    let parsedPart = pathParts[index];

    // while (if) the part starts with `\` remove it and
    // append `.` and then next part from the array to it
    // this should result in `test\\.test` being parsed
    // into `test.test`. This is done so users can escape
    // dots from the dot notation
    while (parsedPart[parsedPart.length - 1] === '\\'
          && pathParts[index + 1] !== undefined
          && pathParts[index + 1] !== null) {
      // remove `\` and append the `.`
      parsedPart = `${parsedPart.slice(0, -1)}.`;
      // increase the index so next iteration it will skip
      // the next path which is about to be added to this path
      index += 1;
      // add the next path to the current one because they are
      // apart of the same object key
      parsedPart += pathParts[index];
    }

    // increase the index so we can continue to the next path
    // in the array
    index += 1;

    // append the parsed path to the results array
    parts.push(parsedPart);
  }

  // return all the parsed paths
  return parts;
}
1007898
function relPath(s) {
  s = str(s);
  var lvls = str(s).replace(/[^/]/g, '').slice(1);
  if (lvls.length < 1 || s.slice(0,1) !== '/') return '.';
  return '..' + _.toArray(lvls).join('..').slice(0,-1);
}
178460
def JoinPath(self, path_segments):
    
    # This is an optimized way to combine the path segments into a single path
    # and combine multiple successive path separators to one.

    # Split all the path segments based on the path (segment) separator.
    path_segments = [
        segment.split(self.PATH_SEPARATOR) for segment in path_segments]

    # Flatten the sublists into one list.
    path_segments = [
        element for sublist in path_segments for element in sublist]

    # Remove empty path segments.
    path_segments = list(filter(None, path_segments))

    return '{0:s}{1:s}'.format(
        self.PATH_SEPARATOR, self.PATH_SEPARATOR.join(path_segments))
993943
function parsePath(path) {
    if (!path) return
    if (path.indexOf(',') == -1) {
        return {
            path : path.replace(/\s/g, '')
        }
    } else {
        let segments = path.split(","),
            vars = segments.slice(1)
        return {
            path: segments[0].replace(/\s/g, ''),
            vars: vars.map(o=>o.replace(/\s/g, ''))
        }
    }
}
214502
def path_join(*args):
    """"""
    return SEP.join((x for x in args if x not in (None, ''))).strip(SEP)
1026776
def get_element(source, path, separator=r'[/.]'):
    
    return _get_element_by_names(source, re.split(separator, path))