regex_find
Builtin index · Collections & strings
result = regex_find(s, pattern)
Input: s, pattern · Output: result
What it is
s and pattern are Strs.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = regex_find(s, pattern) | s Strnot documented yetpattern Strnot documented yet | Str —the first match | Returns a Str (the first match) or none — not an empty string, so "matched empty" and "did not match" stay apart. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
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")
3from collections-strings
How it works
none rather than an empty string when nothing matches, so "matched empty" and "did not match" stay distinguishable — index_of's own convention.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.