# Concatenation and Repetition

These operations build a new Term from existing ones by joining them end to end or repeating one. Every result is a Term you can pass to the next call.

## Concatenation

Concatenation builds a new Term by **joining strings end-to-end in order**.

Example:

<CodeTabs defaultValue="java">
<CodeTabs.Tab value="java" label="Java">
```java
RegexSolverClient client = RegexSolverClient.builder()
    .apiToken(System.getenv("REGEXSOLVER_API_TOKEN"))
    .build();
Term a = Term.regex("ab");
Term b = Term.regex("c.*");
Term c = Term.regex("de");

OperationOptions operationOptions = OperationOptions.builder()
        .responseFormat(ResponseFormat.REGEX);
Term result = client.concat(List.of(a, b, c), operationOptions);

System.out.println(result); // regex=abc.*de
```
</CodeTabs.Tab>

<CodeTabs.Tab value="javascript" label="JavaScript">
```javascript
const client = new RegexSolverClient({ apiToken: process.env.REGEXSOLVER_API_TOKEN });
const a = Term.regex("ab");
const b = Term.regex("c.*");
const c = Term.regex("de");

const result = await client.concat(a, b, c, { responseFormat: ResponseFormat.REGEX });

console.log(result); // regex=abc.*de
```
</CodeTabs.Tab>

<CodeTabs.Tab value="python" label="Python">
```python
client = RegexSolverClient(api_token=os.getenv("REGEXSOLVER_API_TOKEN"))
a = Term.regex(r"ab")
b = Term.regex(r"c.*")
c = Term.regex(r"de")

result = client.concat(a, b, c, response_format=ResponseFormat.REGEX)

print(result) # regex=abc.*de
```
</CodeTabs.Tab>
</CodeTabs>

## Repeat

Repeat a Term between **`min` and `max` times**.

* `min` is required
* `max` is optional
* If `max` is `null`, the repetition is **unbounded**

Example:

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

OperationOptions operationOptions = OperationOptions.builder()
        .responseFormat(ResponseFormat.REGEX);

Term r1 = client.repeat(term, 2, 4, operationOptions);
System.out.println(r1); // regex=(abc){2,4}

Term r2 = client.repeat(term, 1, null, operationOptions);
System.out.println(r2); // regex=(abc)+
```
</CodeTabs.Tab>

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

const r1 = await client.repeat(term, 2, 4, { responseFormat: ResponseFormat.REGEX });
console.log(r1); // regex=(abc){2,4}

const r2 = await client.repeat(term, 1, null, { responseFormat: ResponseFormat.REGEX });
console.log(r2); // regex=(abc)+
```
</CodeTabs.Tab>

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

r1 = client.repeat(term, 2, 4, response_format=ResponseFormat.REGEX)
print(r1) # regex=(abc){2,4}

r2 = client.repeat(term, 1, None, response_format=ResponseFormat.REGEX)
print(r2) # regex=(abc)+
```
</CodeTabs.Tab>
</CodeTabs>
