Qu

regex_count

Builtin index · Collections & strings

result = regex_count(s, pattern)

Input: s, pattern · Output: result

What it is

s and pattern are Strs.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = regex_count(s, pattern)
s Strnot documented yet
pattern Strnot documented yet
result number
Returns a number: how many non-overlapping matches occur.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

print(regex_match("abc123", "[0-9]+"))     # true

print(regex_count("a1b22c333", "[0-9]+"))  # 3

output
true
3

from agent-guide

s = "sensor_1: 12.4, sensor_2: 9.8, sensor_3: 15.0"
print(regex_match(s, "sensor_[0-9]+"))    # true

print(regex_find(s, "[0-9]+\.[0-9]+"))    # "12.4"

print(regex_split(s, ", *"))              # 3-piece split on each comma

print(regex_count(s, "sensor_"))          # 3

output
true
12.4
("sensor_1: 12.4", "sensor_2: 9.8", "sensor_3: 15.0")
3

from collections-strings

figure()
polygon([0.0, 1.0, 1.0], [0.0, 0.0, 1.0], fill = "#00ff00", alpha = 1.0)
figure_size(200, 150, unit = "mm")
polygon([2.0, 3.0, 3.0], [0.0, 0.0, 1.0], fill = "#0000ff", alpha = 1.0)
savefig(tmp_svg)
print(regex_count(read_all_text(tmp_svg), "<polygon"))   # 2, not 1

from agent-guide