### Question:
Resource extends DecoratedTypeElement implements HasFacets, PathContext { protected static List<PathSegment> extractPathComponents(String path) { List<PathSegment> components = new ArrayList<PathSegment>(); if (path != null) { int inBrace = 0; boolean definingRegexp = false; StringBuilder name = new StringBuilder(); StringBuilder regexp = new StringBuilder(); for (int i = 0; i < path.length(); i++) { char ch = path.charAt(i); if (ch == '{') { inBrace++; } else if (ch == '}') { inBrace--; if (inBrace == 0) { definingRegexp = false; } } else if (inBrace == 1 && ch == ':') { definingRegexp = true; continue; } if (definingRegexp) { regexp.append(ch); } else if (!Character.isWhitespace(ch) && ch != '/') { name.append(ch); } if (i + 1 == path.length() || (ch == '/' && !definingRegexp)) { String trimmed = name.toString().trim(); if (!trimmed.isEmpty()) { components.add(new PathSegment(trimmed, regexp.length() > 0 ? regexp.toString().trim() : null)); } name = new StringBuilder(); regexp = new StringBuilder(); } } } return components; } protected  Resource(TypeElement delegate, String path, TypeVariableContext variableContext, EnunciateJaxrsContext context); EnunciateJaxrsContext getContext(); final String getPath(); List<PathSegment> getPathComponents(); abstract Resource getParent(); Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> getConsumesMediaTypes(); Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> getProducesMediaTypes(); Set<ResourceParameter> getResourceParameters(); List<ResourceMethod> getResourceMethods(); List<ResourceMethod> getResourceMethods(boolean loadDescendants); List<SubResourceLocator> getResourceLocators(); Set<Facet> getFacets(); Set<String> getSecurityRoles();  }### Answer:
@Test public void testExtractPathComponents() throws Exception { List<PathSegment> components = Resource.extractPathComponents("/path/{id}"); assertEquals(2, components.size()); assertEquals("path", components.get(0).getValue()); assertNull(components.get(0).getRegex()); assertEquals("{id}", components.get(1).getValue()); assertNull(components.get(1).getRegex()); components = Resource.extractPathComponents("/path/{id: [0-9]+}"); assertEquals(2, components.size()); assertEquals("path", components.get(0).getValue()); assertNull(components.get(0).getRegex()); assertEquals("{id}", components.get(1).getValue()); assertEquals("[0-9]+", components.get(1).getRegex()); components = Resource.extractPathComponents("/path/{id: [0-9]+}/other"); assertEquals(3, components.size()); assertEquals("path", components.get(0).getValue()); assertNull(components.get(0).getRegex()); assertEquals("{id}", components.get(1).getValue()); assertEquals("[0-9]+", components.get(1).getRegex()); assertEquals("other", components.get(2).getValue()); assertNull(components.get(2).getRegex()); components = Resource.extractPathComponents("/path/{id: [0-9]+}/other/"); assertEquals(3, components.size()); assertEquals("path", components.get(0).getValue()); assertNull(components.get(0).getRegex()); assertEquals("{id}", components.get(1).getValue()); assertEquals("[0-9]+", components.get(1).getRegex()); assertEquals("other", components.get(2).getValue()); assertNull(components.get(2).getRegex()); components = Resource.extractPathComponents("/path/{file: [\\/A-Za-z0-9_\\-\\.]+.jpg}"); assertEquals(2, components.size()); assertEquals("path", components.get(0).getValue()); assertNull(components.get(0).getRegex()); assertEquals("{file}", components.get(1).getValue()); assertEquals("[\\/A-Za-z0-9_\\-\\.]+.jpg", components.get(1).getRegex()); }