PathCreator { static String[] findVars(final String path) { final List<String> vars = new ArrayList<>(); final char[] arr = path.toCharArray(); char lastChar = 0; int start = -1; for (int i = 0; i < arr.length; i++) { final char c = arr[i]; if (start == -1 && c == '{' && lastChar == '$') { start = i + 1; } else if (start != -1 && c == '}') { vars.add(new String(arr, start, i - start)); start = -1; } lastChar = c; } String[] varsArr = new String[vars.size()]; varsArr = vars.toArray(varsArr); return varsArr; }    }
@Test public void testFindVars() { final String[] vars = PathCreator.findVars("/temp/${feed}-FLAT/${pipe}_less-${uuid}/${searchId}"); Assert.assertEquals(4, vars.length); Assert.assertEquals("feed", vars[0]); Assert.assertEquals("pipe", vars[1]); Assert.assertEquals("uuid", vars[2]); Assert.assertEquals("searchId", vars[3]); }