STRING::FIND_ALL_STRING_SUBMATCH 1g 2023 laplante@plcb.ca GOWEB — Find All Regex Matches with Submatches


title: “STRING::FIND_ALL_STRING_SUBMATCH” version: “1.0.0” date: 2023 author: “laplante@plcb.ca” section: “1g” category: “GOWEB”


Name

string::find_all_string Find All Regex Matches with Submatches

Synopsis

string::find_all_string_submatch(string, re/.../ [, nbmatch: int])
find_all_string_submatch(string, re/.../ [, nbmatch: int])
string::findAllStringSubMatch(string, re/.../ [, nbmatch: int])
findAllStringSubMatch(string, re/.../ [, nbmatch: int])

Description

The find_all_string_submatch function matches an input string against a given regular expression and returns an array of arrays, where each inner array contains:

  1. The full match.
  2. All captured submatches from the regular expression.

---

## Description

The `find_all_string_submatch` function matches an input string against a given regular expression and returns an **array of arrays**, where each inner array contains:

1. The **full match**.
2. All **captured submatches** from the regular expression.

The optional `nbmatch` parameter can be used to limit the number of matches returned.

If `nbmatch` is omitted, **all matches** are returned.

---

### Parameters

- **string** *(string, required)*
  The input string to search.

- **re/.../** *(regular expression, required)*
  The regular expression pattern to apply.

- **nbmatch** *(integer, optional)*
  The maximum number of matches to return:
  - `0` → Return no matches (empty array).
  - `>0` → Return at most that many matches.
  - `<0` → Return all matches (default behavior).

---

## Examples

```plaintext
res={{
    match("1962-06 56a Laplante 65b chantal 72c caroline", re/(\d\d\d\d-\d\d)/)
}};

Returns:

res = [["1962-06","1962-06"]]

res={{
    match("514-945-1779", re/(\d\d\d)-(\d+)-(\d+)/)
}};

Returns:

res = [["514-945-1779","514","945","1779"]]

res={{
    match(re/xysn/, "pierre");
}};

Returns:

res = []

res={{
    match("Pierre  56a Laplante 65b chantal 72c caroline", "");
}};

Returns:

.*string::match : regular expression is empty

res={{
    match("Pierre  56a Laplante 65b chantal 72c caroline", re/(.)(..)/);
}};

Returns: (full match, first capture, second capture)

res = [["Pie","P","ie"],["rre","r","re"],["  5"," "," 5"],["6a ","6","a "],["Lap","L","ap"],["lan","l","an"],["te ","t","e "],["65b","6","5b"],[" ch"," ","ch"],["ant","a","nt"],["al ","a","l "],["72c","7","2c"],[" ca"," ","ca"],["rol","r","ol"],["ine","i","ne"]]

res={{
    match("Pierre  56a Laplante 65b chantal 72c caroline", re/(\d+)([a-z]+)/);
}};

Returns:

res = [["56a","56","a"],["65b","65","b"],["72c","72","c"]]

res={{
    match("Pierre  56a Laplante 65b chantal 72c caroline", re/(\d+)([a-z]+)/, nbmatch:2);
}};

Returns:

res = [["56a","56","a"],["65b","65","b"]]

res={{
    match("Pierre  56a Laplante 65b chantal 72c caroline", re/(\d+)([a-z]+)/, nbmatch:0);
}};

Returns:

res = []

res={{
    match("Pierre  56a Laplante 65b chantal 72c caroline", re/(\d+)([a-z]+)/, nbmatch:10000);
}};

Returns:

res = [["56a","56","a"],["65b","65","b"],["72c","72","c"]]

Author


See Also


Version History