Function: split_text

Function: split_text

since 0.3.8


 split_text(some_string, match: regular expression, in_context: regular expression)

Split text by keeping the parts between separators matching a regular expression. The function returns a list of parts.

When the split_text is used many times with the same match or in_context values it is more efficient to declare these as default arguments:

 my_break := split_text@(match: ",")
 my_break("a,b,c") # called many times

This way the regular expression is only compiled once.

Split vs. break

The function break_text does the opposite of split_text, keeping the parts mathing the regular expression, instead of the parts between it.


Parameter Type Description
input string String to replace in.
match regex Regular expression to match.
include_empty boolean (default: true) If set to false, remove all empty parts


 split_text(match: ",", "ab,cd,,ef")                       ==  ["ab","cd","","ef"]
 split_text(match: ",", "ab,cd,,ef", include_empty:false)  ==  ["ab","cd","ef"]
 split_text(match: "a", "banana")  ==  ["b","n","n",""]
 break_text(match: "a", "banana")  ==  ["a","a","a"]

See also

break_text Break text into parts each matching a regular expression.

For working with comma separated lists, such as those from multiple choice fields, there are special functions:

chosen Is the given choice selected in a multiple choice value?
count_chosen Count then number of choices selected in a multiple choice value.
require_choice Require that at least one of the given choices is selected.
exclusive_choice Require that at most one of the given choices is selected.
require_exclusive_choice Require that exactly one of the given choices is selected.
remove_choice Remove the given choices from a multiple choice value.