These operations build a new Term from existing ones using classic set operations. They are the core of the API, and every result is a Term you can pass to the next call.
Union
Returns a Term representing strings that appear in any of the provided Terms (logical OR).
Example:
Code
RegexSolverClient client = RegexSolverClient.builder() .apiToken(System.getenv("REGEXSOLVER_API_TOKEN")) .build();Term a = Term.regex("abe");Term b = Term.regex("cde");Term c = Term.regex("efe");OperationOptions options = OperationOptions.builder() .responseFormat(ResponseFormat.REGEX);Term result = client.union(List.of(a, b, c), options);System.out.println(result); // regex=(ab|cd|ef)e
Intersection
Returns a Term representing only strings that appear in all of the provided Terms (logical AND).
Example:
Code
RegexSolverClient client = RegexSolverClient.builder() .apiToken(System.getenv("REGEXSOLVER_API_TOKEN")) .build();Term a = Term.regex("[a-z]{2}");Term b = Term.regex("(ab|cd|efg)");Term c = Term.regex("a.*");OperationOptions options = OperationOptions.builder() .responseFormat(ResponseFormat.REGEX);Term result = client.intersection(List.of(a, b, c), options);System.out.println(result); // regex=ab
Difference
Returns a Term representing strings that are in the first Term but not in the second one.
Example:
Code
RegexSolverClient client = RegexSolverClient.builder() .apiToken(System.getenv("REGEXSOLVER_API_TOKEN")) .build();Term a = Term.regex("(cat|dog|owl)");Term b = Term.regex("dog");OperationOptions options = OperationOptions.builder() .responseFormat(ResponseFormat.REGEX);Term result = client.difference(a, b, options);System.out.println(result); // regex=(cat|owl)
Complement
Returns a Term representing every string that is not in the given Term's language.
Example:
Code
RegexSolverClient client = RegexSolverClient.builder() .apiToken(System.getenv("REGEXSOLVER_API_TOKEN")) .build();Term term = Term.regex(".*a.*");OperationOptions options = OperationOptions.builder() .responseFormat(ResponseFormat.REGEX);Term result = client.complement(term, options);System.out.println(result); // regex=[^a]*