private static A convert(String regex) {
		List<String> groups = splitAndGroup(regex);
		A curr = new A();

		if (groups.size() > 1) {
			for (String s : groups) {
				A tmp = convert(s);
				curr.stateNames.addAll(tmp.stateNames);
				curr.transitionsForState.putAll(tmp.transitionsForState);
				curr.addTransition(curr.begin, Automaton.EPSILON, tmp.begin);
				curr.addTransition(tmp.end, Automaton.EPSILON, curr.end);
			}
		} else {
			String prev = curr.begin;
			for (int i = 0; i < regex.length(); ++i) {
				String s1;
				String s2;
				if (isEscapedAt(regex, i)) {
					s1 = createNewState();
					s2 = createNewState();
					curr.stateNames.add(s1);
					curr.stateNames.add(s2);
					curr.addTransition(s1, Character.toString(unescape(regex.charAt(i))), s2);
				} else {
					if (regex.charAt(i) == '\\')
						continue;

					if (regex.charAt(i) != '(') {
						s1 = createNewState();
						s2 = createNewState();
						curr.stateNames.add(s1);
						curr.stateNames.add(s2);
						curr.addTransition(s1, regex.charAt(i) == '$' ? Automaton.EPSILON : Character.toString(regex.charAt(i)), s2);
					} else {
						int j = findMatchingParenthesis(regex, i);
						A tmp = convert(regex.substring(i + 1, j));
						curr.stateNames.addAll(tmp.stateNames);
						curr.transitionsForState.putAll(tmp.transitionsForState);
						s1 = tmp.begin;
						s2 = tmp.end;
						i = j;
						
					}
				}

				if (i + 1 < regex.length() && regex.charAt(i + 1) == '*') {
					String innerBegin = s1;
					String innerEnd = s2;
					curr.stateNames.add(s1 = createNewState());
					curr.stateNames.add(s2 = createNewState());

					curr.addTransition(s1, Automaton.EPSILON, innerBegin);
					curr.addTransition(innerEnd, Automaton.EPSILON, s2);
					curr.addTransition(s1, Automaton.EPSILON, s2);
					curr.addTransition(innerEnd, Automaton.EPSILON, innerBegin);

					++i;
				}
				// /
				curr.addTransition(prev, Automaton.EPSILON, s1);
				prev = s2;

			}
			curr.addTransition(prev, Automaton.EPSILON, curr.end);
		}

		return curr;
	}