Reference · Regular expressions

re.find_all

signature
re.find_all(str, str, str | null=) -> list

What it does

Every match of a pattern in the text, from left to right, as a list of matches, each { text, start, end, groups, named } as re.find gives it. No match is the empty list. The flags come last: "i", "m", "s".

Examples

print(re.find_all("a1 b22 c333", "\\d+") | map((m) => m.text))print(re.find_all("@ann and @bob", "@(\\w+)") | map((m) => m.groups[0]))print(re.find_all("x1y2", "(?<l>[a-z])(?<n>\\d)") | map((m) => m.named))print(re.find_all("hello", "\\d+"))
output
["1", "22", "333"]["ann", "bob"][{ l: "x", n: "1" }, { l: "y", n: "2" }][]

Edge cases

print(re.find_all("aaa", "aa") | map((m) => [m.start, m.end]))print(re.find_all("abc", "") | map((m) => m.start))print(re.find_all("añob", "[ob]") | map((m) => [m.start, m.end]))print(re.find_all("a\nb\nc", "^\\w$", "m") | map((m) => m.text))
output
[[0, 2]][0, 1, 2, 3][[2, 3], [3, 4]]["a", "b", "c"]

Errors

No match is [], not an error. A pattern that is not supported (lookaround, backreferences, \p{...}, a bad escape, a bad flag) is a runtime error, not an error value, as is a text that is not a string: null from a missing field stops the request, so give it a default first. See re.test for the list.

this one fails
print(re.find_all(null, "\\w+"))
output
line 1: `re.find_all` expects a str as argument 1, got null
this one fails
print(re.find_all("abc", "\\p{L}"))
output
line 1: `re.find_all`: Unicode classes (\p{...}) are not supported

Chaining

The text comes first in a pipeline, and the list goes on to map, len or join:

print("tags: #a #b #c" | re.find_all("#(\\w+)") | map((m) => m.groups[0]) | join(", "))print("a-b-c" | re.find_all("-") | len)print("The year 1999 and 2026" | re.find_all("\\d{4}") | map((m) => int(m.text)) | sum)
output
a, b, c24025

See also

re.find, re.test, re.replace, re.split, map

Thread
8Useful? Like it, or add to its thread below.

Thread 0 posts

On re.find_all(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo