if (hex.length() == 2)
if (hex.length() == 1) sb.append("x0" + hex); else if (hex.length() == 2)
  private static String cleanRegexp(StringValue regexp, boolean isComments)  {    int len = regexp.length();    StringBuilder sb = new StringBuilder();    char quote = 0;    for (int i = 0; i < len; i++) {      char ch = regexp.charAt(i);      switch (ch) {      case '\\':        sb.append(ch);        if (i + 1 < len) {          i++;          ch = regexp.charAt(i);          if (ch == '0' ||	      '1' <= ch && ch <= '3' && i + 1 < len && '0' <= regexp.charAt(i + 1) && ch <= '7') {            // Java's regexp requires \0 for octal            // sb.append('\\');            sb.append('0');            sb.append(ch);          }          else if (ch == 'x' && i + 1 < len && regexp.charAt(i + 1) == '{') {            int tail = regexp.indexOf('}', i + 1);            if (tail > 0) {              StringValue hex = regexp.substring(i + 2, tail);              if (hex.length() == 2)                sb.append("x" + hex);              else if (hex.length() == 4)                sb.append("u" + hex);              else                throw new QuercusRuntimeException(L.l("illegal hex escape"));              i = tail;            }            else {              sb.append("\\x");            }          }          else            sb.append(ch);        }        break;      case '[':        if (quote == '[') {          if (i + 1 < len && regexp.charAt(i + 1) == ':') {            String test = regexp.substring(i).toString();            boolean hasMatch = false;            for (int j = 0; j < POSIX_CLASSES.length; j++) {              if (test.startsWith(POSIX_CLASSES[j])) {                hasMatch = true;                sb.append(REGEXP_CLASSES[j]);                i += POSIX_CLASSES[j].length() - 1;              }            }            if (! hasMatch)              sb.append("\\[");          }          else            sb.append("\\[");        }        else if (i + 1 < len && regexp.charAt(i + 1) == '['		 && ! (i + 2 < len && regexp.charAt(i + 2) == ':')) {	  // XXX: check regexp grammar	  // php/151n          sb.append("[\\[");	  i += 1;	}        else if (i + 2 < len &&		 regexp.charAt(i + 1) == '^' &&		 regexp.charAt(i + 2) == ']') {          sb.append("[^\\]");	  i += 2;	}        else          sb.append('[');        if (quote == 0)          quote = '[';        break;      case '#':        if (quote == '[' && isComments)          sb.append("\\#");        else          sb.append(ch);        break;      case ']':        sb.append(ch);        if (quote == '[')          quote = 0;        break;      case '{':        if (i + 1 < len &&            ('0' <= (ch = regexp.charAt(i + 1)) && ch <= '9' || ch == ',')) {          sb.append("{");          for (i++;               i < len &&               ('0' <= (ch = regexp.charAt(i)) && ch <= '9' || ch == ',');               i++) {            sb.append(ch);          }          if (i < len)            sb.append(regexp.charAt(i));        }        else {          sb.append("\\{");        }        break;      case '}':        sb.append("\\}");        break;      default:        sb.append(ch);      }    }    return sb.toString();  }