stanfordnlp/CoreNLP · error · IllegalArgumentException

valueSplit: " + valueRegex + " doesn't match " + str

Error message

valueSplit: " + valueRegex + " doesn't match " + str

What it means

StringUtils.valueSplit splits a string into values separated by a separator regex, matching each value against a valueRegex. When the remaining string does not start with a match of valueRegex, it throws IllegalArgumentException('valueSplit: <valueRegex> doesn't match <str>'), i.e. the data no longer conforms to the value/separator alternation.

Solutions

  1. Fix the input string so values and separators strictly alternate with no trailing separator
  2. Broaden valueRegex to accept all characters that appear in your values (e.g. '[0-9.]+')
  3. Preprocess the input: trim trailing separators and strip unexpected whitespace before calling valueSplit

Example fix

// before
StringUtils.valueSplit("[0-9]+", "\\s*,\\s*", "1,2,3,"); // trailing comma
// after
String s = StringUtils.trim("1,2,3,"); s = s.replaceAll(",\\s*$", "");
StringUtils.valueSplit("[0-9]+", "\\s*,\\s*", s);
Defensive patterns

Strategy: validation

Validate before calling

if (str.endsWith(",")) str = str.substring(0, str.length() - 1); // strip trailing separator
if (!str.matches("^" + valueRegex + ".*")) throw new IllegalArgumentException("Bad start: " + str);

Try / catch

try {
  List<String> vals = StringUtils.valueSplit(valueRegex, sepRegex, str);
} catch (IllegalArgumentException e) {
  log.error("Cannot split value string: " + e.getMessage());
}

Prevention

When it happens

Trigger: Calling valueSplit(valueRegex, separatorRegex, str) where after consuming a separator the remaining text does not begin with a value matching valueRegex — e.g. a trailing separator, an empty field, or a value with characters outside the value pattern.

Common situations: Lists written with trailing commas like 'a,b,c,'; user-supplied strings containing unexpected characters; regexes too narrow for real data (e.g. value regex '[0-9]+' but data contains '3.5').

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/8c8a68e9d6b19fbd. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/StringUtils.java:623

   *  @param str The String to split
   *  @param valueRegex Must match a token. You may wish to let it match the empty String
   *  @param separatorRegex Must match a separator
   *  @return The List of tokens
   *  @throws IllegalArgumentException if str cannot be tokenized by the two regex
   */
  public static List<String> valueSplit(String str, String valueRegex, String separatorRegex) {
    Pattern vPat = Pattern.compile(valueRegex);
    Pattern sPat = Pattern.compile(separatorRegex);
    List<String> ret = new ArrayList<>();
    while ( ! str.isEmpty()) {
      Matcher vm = vPat.matcher(str);
      if (vm.lookingAt()) {
        ret.add(vm.group());
        str = str.substring(vm.end());
        // String got = vm.group();
        // log.info("vmatched " + got + "; now str is " + str);
      } else {
        throw new IllegalArgumentException("valueSplit: " + valueRegex + " doesn't match " + str);
      }
      if ( ! str.isEmpty()) {
        Matcher sm = sPat.matcher(str);
        if (sm.lookingAt()) {
          str = str.substring(sm.end());
          // String got = sm.group();
          // log.info("smatched " + got + "; now str is " + str);
        } else {
          throw new IllegalArgumentException("valueSplit: " + separatorRegex + " doesn't match " + str);
        }
      }
    } // end while
    return ret;
  }


  /**
   * Return a String of length a minimum of totalChars characters by

View on GitHub (pinned to 1b7edd19c4)