{"record":{"id":"8c8a68e9d6b19fbd","repo":"stanfordnlp/CoreNLP","slug":"valuesplit-valueregex-doesn-t-match-s","errorCode":null,"errorMessage":"valueSplit: \" + valueRegex + \" doesn't match \" + str","messagePattern":"valueSplit: \" \\+ valueRegex \\+ \" doesn't match \" \\+ str","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":623,"sourceCode":"   *  @param str The String to split\n   *  @param valueRegex Must match a token. You may wish to let it match the empty String\n   *  @param separatorRegex Must match a separator\n   *  @return The List of tokens\n   *  @throws IllegalArgumentException if str cannot be tokenized by the two regex\n   */\n  public static List<String> valueSplit(String str, String valueRegex, String separatorRegex) {\n    Pattern vPat = Pattern.compile(valueRegex);\n    Pattern sPat = Pattern.compile(separatorRegex);\n    List<String> ret = new ArrayList<>();\n    while ( ! str.isEmpty()) {\n      Matcher vm = vPat.matcher(str);\n      if (vm.lookingAt()) {\n        ret.add(vm.group());\n        str = str.substring(vm.end());\n        // String got = vm.group();\n        // log.info(\"vmatched \" + got + \"; now str is \" + str);\n      } else {\n        throw new IllegalArgumentException(\"valueSplit: \" + valueRegex + \" doesn't match \" + str);\n      }\n      if ( ! str.isEmpty()) {\n        Matcher sm = sPat.matcher(str);\n        if (sm.lookingAt()) {\n          str = str.substring(sm.end());\n          // String got = sm.group();\n          // log.info(\"smatched \" + got + \"; now str is \" + str);\n        } else {\n          throw new IllegalArgumentException(\"valueSplit: \" + separatorRegex + \" doesn't match \" + str);\n        }\n      }\n    } // end while\n    return ret;\n  }\n\n\n  /**\n   * Return a String of length a minimum of totalChars characters by","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L605-L641","documentation":"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.","triggerScenarios":"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.","commonSituations":"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').","solutions":["Fix the input string so values and separators strictly alternate with no trailing separator","Broaden valueRegex to accept all characters that appear in your values (e.g. '[0-9.]+')","Preprocess the input: trim trailing separators and strip unexpected whitespace before calling valueSplit"],"exampleFix":"// before\nStringUtils.valueSplit(\"[0-9]+\", \"\\\\s*,\\\\s*\", \"1,2,3,\"); // trailing comma\n// after\nString s = StringUtils.trim(\"1,2,3,\"); s = s.replaceAll(\",\\\\s*$\", \"\");\nStringUtils.valueSplit(\"[0-9]+\", \"\\\\s*,\\\\s*\", s);","handlingStrategy":"validation","validationCode":"if (str.endsWith(\",\")) str = str.substring(0, str.length() - 1); // strip trailing separator\nif (!str.matches(\"^\" + valueRegex + \".*\")) throw new IllegalArgumentException(\"Bad start: \" + str);","typeGuard":null,"tryCatchPattern":"try {\n  List<String> vals = StringUtils.valueSplit(valueRegex, sepRegex, str);\n} catch (IllegalArgumentException e) {\n  log.error(\"Cannot split value string: \" + e.getMessage());\n}","preventionTips":["Make valueRegex permissive enough for all real-world characters in values","Normalize input (trim whitespace, remove trailing separators) before splitting","Test valueSplit against the actual data format, not the assumed one"],"tags":["java","regex","string-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}