public static Expression create(final String value) {

    /* remove the start and end braces */
    final String expression = stripBraces(value);
    if (expression == null || expression.isEmpty()) {
      throw new IllegalArgumentException("an expression is required.");
    }

    /* Check if the expression is too long */
    if (expression.length() > MAX_EXPRESSION_LENGTH) {
      throw new IllegalArgumentException(
          "expression is too long. Max length: " + MAX_EXPRESSION_LENGTH);
    }

    /* create a new regular expression matcher for the expression */
    String variableName = null;
    String variablePattern = null;
    String operator = null;
    Matcher matcher = EXPRESSION_PATTERN.matcher(value);
    if (matcher.matches()) {
      /* grab the operator */
      operator = matcher.group(2).trim();

      /* we have a valid variable expression, extract the name from the first group */
      variableName = matcher.group(3).trim();
      if (variableName.contains(":")) {
        /* split on the colon and ensure the size of parts array must be 2 */
        String[] parts = variableName.split(":", 2);
        variableName = parts[0];
        variablePattern = parts[1];
      }

      /* look for nested expressions */
      if (variableName.contains("{")) {
        /* nested, literal */
        return null;
      }
    }

    /* check for an operator */
    if (PATH_STYLE_OPERATOR.equalsIgnoreCase(operator)) {
      return new PathStyleExpression(variableName, variablePattern);
    }

    /* default to simple */
    return SimpleExpression.isSimpleExpression(value)
        ? new SimpleExpression(variableName, variablePattern)
        : null; // Return null if it can't be validated as a Simple Expression -- Probably a Literal
  }
@Test
  void malformedExpression() {
    String[] malformedStrings = {"{:}", "{str1:}", "{str1:{:}", "{str1:{str2:}"};

    for (String malformed : malformedStrings) {
      try {
        Expressions.create(malformed);
      } catch (Exception e) {
        assertThatObject(e).isNotInstanceOf(ArrayIndexOutOfBoundsException.class);
      }
    }
  }