# Regular Expression

A **Regular Expression** is a sequence of characters that forms a search pattern. Regular Expressions are very similar across all programming languages.

Regular expressions enable you to not only match or validate text, but to also extract specific information for further processing.

Grouping constructs can be used in regular expressions to search for patterns (groups of characters) within an input string. It is even possible to extract subgroups (nested groups) from an input string.

Defining and capturing groups of characters are done by using parentheses `()` together with specific quantifiers. Any pattern inside a pair of parentheses will be captured as a group as per the quantifiers being used. When multiple groups are defined, the results of the captured groups are in the order in which they are defined (in order of open parenthesis).

***

## Properties

### Action

The function will always return the *index* and the *length* of found matches.

Options:

* *First match* only returns the information for the first match found.
* *All matches* returns a list of all matches found.
* *Replace* will use the 'Replace with' field to replace content matching the pattern.
* *Split* will split the string at the matched pattern. The matched pattern is not returned. If you are, for example, looking for a comma to split a string (`1,2`) by, then a list containing two rows is returned. The comma will not be returned.

### Input string

The string on which to perform the regular expression operations.

### Expression

The regular expression pattern to apply to the input string.

See some [examples](http://regexlib.com/).

### Options

A set of standard Regular Expression options to pick from.

Here is a [detailed description](http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx) of these options.

### Replace with

A string to replace matched content with.

Only displayed when [Action](#action) is 'Replace'.

### Loop results

If selected, the results will be returned line by line; otherwise, a list containing all the results will be created.

Only displayed when[ Action](#action) is 'All matches' or 'Split'.

***

## Definition and Debug Values

The Definition variables that are available from the Regular Expression function include those Index and Value variables for any defined groups:

<div align="left"><figure><img src="/files/YXdggkSyWxsshBRwXfaH" alt=""><figcaption></figcaption></figure></div>

When debugging a Regular Expression, the debug values will indicate the number of matches found and the specific details thereof, including the position in a string (Index) and the value of the capture.

### Example

The screenshot below shows an extract of Debug Values for the following Regular Expression:

**Expression:** `\w+ (\d+)`

**Input string:** `Jan 1987 May 1969 Aug 2011`

<figure><img src="/files/vnqlLww5z2JabMWolb8i" alt="Debug Values"><figcaption><p>Debug Values</p></figcaption></figure>

***

## Links

[Wikipedia: Regular Expressions](http://en.wikipedia.org/wiki/Regular_expression)

[RegularExpressions.info](http://www.regular-expressions.info/reference.html)

[Regexlib.com](http://regexlib.com/CheatSheet.aspx)

[gskinner.com](http://gskinner.com/RegExr/)

[RegexOne.com](https://regexone.com/lesson/capturing_groups)

[Microsoft.com - Grouping Constructs](https://docs.microsoft.com/en-us/dotnet/standard/base-types/grouping-constructs-in-regular-expressions)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.linx.software/reference/plugins/text/content/regularexpression.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
