exec

Summary

Matches the regular expression pattern against some text and returns the next match (or null if no matches remain).

Usage

public string? exec(string value)

Returns

The next match or "null" (if there are no remaining matches)

Parameters

value

The string to match the regular expression pattern against.

Description

Matches the regular expression pattern against some text and returns the next match or null (if there are no remaining matches).

To return all matches, use execAll. However, unlike execAll, exec allows you to check and set the lastIndex property to manually check or begin the match at a specified location. Furthermore, exec allows tighter control over large text so that regular expression matching can be started or stopped manually.

Examples

Basic Usage
1
2
3
4
5
import System;
 
System.RegExp re = /^abc/;
Console.log(re.exec("abc")); // "abc"
Console.log(re.exec("xyz")); // null
Using 'lastIndex' to begin matching from a custom location
1
2
3
4
5
import System;
 
System.RegExp re = /.a./g;
re.lastIndex = 11;
Console.log(re.exec("There is a way")); // "way"

Share

HTML | BBCode | Direct Link