# RegExp

## Overview

The `RegExp` object in JavaScript provides powerful tools for pattern matching and text processing. It allows developers to define patterns for searching and manipulating strings, supporting modifiers such as global searches, case-insensitivity, and multiline matching. Key properties include the pattern source, flags indicating active modifiers, and the index position for the next match.

Core functionality includes the `exec()` method, which searches for a pattern and returns the matched value while keeping track of the match position, and the `test()` method, which checks if a pattern exists in a string, returning a boolean result.

For more information see: [RegExp (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp).

## Properties Summarized

| Type                                                       | Name                      | Summary                                                           |
| ---------------------------------------------------------- | ------------------------- | ----------------------------------------------------------------- |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [global](#global)         | Specifies if the "g" modifier is set.                             |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [ignoreCase](#ignorecase) | Specifies if the "i" modifier is set.                             |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)   | [lastIndex](#lastindex)   | An integer specifying the index at which to start the next match. |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [multiline](#multiline)   | Specifies if the "m" modifier is set.                             |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [source](#source)         | The text used for pattern matching.                               |

## Methods Summarized

| Type                                                       | Name                         | Summary                                |
| ---------------------------------------------------------- | ---------------------------- | -------------------------------------- |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [exec(string)](#exec-string) | Search a string for a specified value. |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [test(string)](#test-string) | Search a string for a specified value. |

## Properties Detailed

### global

Specifies if the "g" modifier is set.

**Type**\
[Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

```js
var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www');
application.output(patt1.global);
```

### ignoreCase

Specifies if the "i" modifier is set.

**Type**\
[Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

```js
var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www');
application.output(patt1.ignoreCase);
```

### lastIndex

An integer specifying the index at which to start the next match.

**Type**\
[Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
var str = 'The rain in Spain stays mainly in the plain';
var patt1 = new RegExp('ain', 'g');
patt1.test(str);
application.output('Match found. index now at: ' + patt1.lastIndex);
```

### multiline

Specifies if the "m" modifier is set.

**Type**\
[Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)

**Sample**

```js
var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www','m');
application.output(patt1.multiline);
```

### source

The text used for pattern matching.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www.','g');
application.output('The regular expression is: ' + patt1.source);
```

## Methods Detailed

### exec(string)

Search a string for a specified value. Returns the found value and remembers the position.

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **string** ;

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) A String representing the found value.

**Sample**

```js
var str='Visit www.servoy.com';
var patt=new RegExp('servoy');
application.output(patt.exec(str));
```

### test(string)

Search a string for a specified value. Returns true or false.

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **string** ;

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) true if a match was found in the string. false otherwise.

**Sample**

```js
var str='Visit www.servoy.com';
var patt=new RegExp('soft');
application.output(patt.test(str)==true);
patt.compile('servoy');
application.output(patt.test(str)==true)
```

***


---

# 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.servoy.com/reference/servoycore/dev-api/js-lib/regexp.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.
