> For the complete documentation index, see [llms.txt](https://hlysine.gitbook.io/readable-regexp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hlysine.gitbook.io/readable-regexp/api-reference/extras.md).

# Extras

## `match`

Include another readable RegExp token in the current expression. This is useful for extracting and re-using common expressions.

Example:

```js
const number = oneOrMore.digit;
const coordinates = match(number).exactly`,`.match(number);
```

This is equivalent to:

```js
const coordinates = oneOrMore.digit.exactly`,`.oneOrMore.digit;
```

`match` can also accept multiple tokens and chain them together, which can be useful for code formatting.

Example:

```js
const filename = match(
    oneOrMore.word,
    exactly`_`,
    oneOrMore.digit,
    exactly`.txt`
);
```

This is equivalent to:

```js
const filename = oneOrMore.word.exactly`_`.oneOrMore.digit.exactly`.txt`;
```

***

## `toString()`

Get the current expression as a RegExp string. This is a terminal operation, which means no more functions can be chained after `toString`, and the string output cannot be converted back to a readable RegExp token.

Back-references are validated when `toString` is called, and an error will be thrown if any of the back-references are invalid.

Example:

```js
const coordinates = oneOrMore.digit.exactly`,`.oneOrMore.digit.toString();
expect(coordinates).toBe("\\d+,\\d+");
```

***

## `toRegExp(flags?)`

Get a RegExp object of the current expression. This is a terminal operation, which means no more functions can be chained after `toRegExp`, and the output cannot be converted back to a readable RegExp token.

Back-references are validated when `toRegExp` is called, and an error will be thrown if any of the back-references are invalid.

You can supply a list of flags to set in the RegExp object:

* `toRegExp('gmi')`
* `` toRegExp`gmi` ``
* `toRegExp(Flag.Global, Flag.MultiLine, Flag.IgnoreCase)`
* `toRegExp('g', 'm', 'i')`

```js
const coordinates = oneOrMore.digit
  .exactly`,`
  .oneOrMore.digit
  .toRegExp(Flag.Global);
console.log(coordinates.exec('[1,2] [3,4]'));  // expect 2 matches
```
