# Analyzing a Term

These operations query a **single Term** and return a boolean or a number rather than a new Term.


<Callout type="note">
Every result on this page is cached on the Term you passed in, so asking the same question twice about the same instance costs a single request. See [Best Practices](/best-practices).
</Callout>

## Empty

Check if the Term matches **no strings**.

The empty check is how most comparisons are resolved. An empty intersection proves two Terms can never match the same string, and an empty difference proves the first Term accepts nothing the second one rejects.

<CodeTabs defaultValue="java">
<CodeTabs.Tab value="java" label="Java">
```java
RegexSolverClient client = RegexSolverClient.builder()
    .apiToken(System.getenv("REGEXSOLVER_API_TOKEN"))
    .build();

client.isEmpty(Term.regex("[]"));   // true, the empty character class matches nothing
client.isEmpty(Term.regex("abc"));  // false
```
</CodeTabs.Tab>

<CodeTabs.Tab value="javascript" label="JavaScript">
```javascript
const client = new RegexSolverClient({ apiToken: process.env.REGEXSOLVER_API_TOKEN });

await client.isEmpty(Term.regex("[]"));   // true, the empty character class matches nothing
await client.isEmpty(Term.regex("abc"));  // false
```
</CodeTabs.Tab>

<CodeTabs.Tab value="python" label="Python">
```python
client = RegexSolverClient(api_token=os.getenv("REGEXSOLVER_API_TOKEN"))

client.is_empty(Term.regex(r"[]"))   # True, the empty character class matches nothing
client.is_empty(Term.regex(r"abc"))  # False
```
</CodeTabs.Tab>
</CodeTabs>

## Totality

Check if the Term matches **all the possible strings**.

Its most common use is the mirror of empty: if the complement of a Term is empty, the Term is total, and a validation rule that is total rejects nothing.

<CodeTabs defaultValue="java">
<CodeTabs.Tab value="java" label="Java">
```java
client.isTotal(Term.regex(".*"));  // true
client.isTotal(Term.regex(".+"));  // false, it does not match the empty string
```
</CodeTabs.Tab>

<CodeTabs.Tab value="javascript" label="JavaScript">
```javascript
await client.isTotal(Term.regex(".*"));  // true
await client.isTotal(Term.regex(".+"));  // false, it does not match the empty string
```
</CodeTabs.Tab>

<CodeTabs.Tab value="python" label="Python">
```python
client.is_total(Term.regex(r".*"))  # True
client.is_total(Term.regex(r".+"))  # False, it does not match the empty string
```
</CodeTabs.Tab>
</CodeTabs>

## Empty String Only

Check if the Term matches **only the empty string**. This separates a Term whose only match is the empty string from one that matches nothing at all, a distinction the empty check cannot make.

<CodeTabs defaultValue="java">
<CodeTabs.Tab value="java" label="Java">
```java
client.isEmptyString(Term.regex(""));    // true
client.isEmptyString(Term.regex("[]"));  // false, this one matches nothing at all
client.isEmptyString(Term.regex("a*"));  // false, it also matches "a", "aa", ...
```
</CodeTabs.Tab>

<CodeTabs.Tab value="javascript" label="JavaScript">
```javascript
await client.isEmptyString(Term.regex(""));    // true
await client.isEmptyString(Term.regex("[]"));  // false, this one matches nothing at all
await client.isEmptyString(Term.regex("a*"));  // false, it also matches "a", "aa", ...
```
</CodeTabs.Tab>

<CodeTabs.Tab value="python" label="Python">
```python
client.is_empty_string(Term.regex(r""))    # True
client.is_empty_string(Term.regex(r"[]"))  # False, this one matches nothing at all
client.is_empty_string(Term.regex(r"a*"))  # False, it also matches "a", "aa", ...
```
</CodeTabs.Tab>
</CodeTabs>

## Cardinality

Compute **how many strings the Term matches**. The result takes one of three forms:

* **Integer**: the language is finite and the exact count fits, so you get the number
* **BigInteger**: the language is finite but the count exceeds what the engine returns exactly
* **Infinite**: the language is unbounded, as with `.*`, `a+` or `.{2,}`

<Callout type="note">
"BigInteger" means the count is too large to return exactly, and not that it is mathematically infinite. A finite language always reports a finite category.
</Callout>

<CodeTabs defaultValue="java">
<CodeTabs.Tab value="java" label="Java">
```java
client.getCardinality(Term.regex("abcde"));    // Integer=1
client.getCardinality(Term.regex("[a-z]"));    // Integer=26
client.getCardinality(Term.regex(".{1,10}"));  // BigInteger
client.getCardinality(Term.regex(".*"));       // Infinite
```
</CodeTabs.Tab>

<CodeTabs.Tab value="javascript" label="JavaScript">
```javascript
await client.getCardinality(Term.regex("abcde"));    // Integer=1
await client.getCardinality(Term.regex("[a-z]"));    // Integer=26
await client.getCardinality(Term.regex(".{1,10}"));  // BigInteger
await client.getCardinality(Term.regex(".*"));       // Infinite
```
</CodeTabs.Tab>

<CodeTabs.Tab value="python" label="Python">
```python
client.get_cardinality(Term.regex(r"abcde"))    # Integer=1
client.get_cardinality(Term.regex(r"[a-z]"))    # Integer=26
client.get_cardinality(Term.regex(r".{1,10}"))  # BigInteger
client.get_cardinality(Term.regex(r".*"))       # Infinite
```
</CodeTabs.Tab>
</CodeTabs>

## Length

Compute the **minimum and maximum length** of strings matched by the Term, returned as `min` and `max`.

Two special cases:

* A Term that matches **nothing** reports `null` for both bounds
* A Term that can produce **infinitely long** strings reports `null` for `max`

<CodeTabs defaultValue="java">
<CodeTabs.Tab value="java" label="Java">
```java
client.getLength(Term.regex("(abc)?d"));  // min=1, max=4
client.getLength(Term.regex(".*"));       // min=0, max=null
client.getLength(Term.regex("[]"));       // min=null, max=null
```
</CodeTabs.Tab>

<CodeTabs.Tab value="javascript" label="JavaScript">
```javascript
await client.getLength(Term.regex("(abc)?d"));  // min=1, max=4
await client.getLength(Term.regex(".*"));       // min=0, max=null
await client.getLength(Term.regex("[]"));       // min=null, max=null
```
</CodeTabs.Tab>

<CodeTabs.Tab value="python" label="Python">
```python
client.get_length(Term.regex(r"(abc)?d"))  # min=1, max=4
client.get_length(Term.regex(r".*"))       # min=0, max=None
client.get_length(Term.regex(r"[]"))       # min=None, max=None
```
</CodeTabs.Tab>
</CodeTabs>
