Env Functions
str_filter
env regex.str_filter(attrs: 'Vec < String >', pattern: 'Regex')
Arguments
attrs: 'Vec < String >'
=> attribute to check for patternpattern: 'Regex'
=> Regex pattern to match
Filter from the string list with only the values matching pattern
env assert_eq(str_filter(["abc", "and", "xyz"], "^a"), ["abc", "and"])
str_match
env regex.str_match(attr: '& str', pattern: 'Regex')
Arguments
attr: '& str'
=> attribute to check for patternpattern: 'Regex'
=> Regex pattern to match
Check if the given pattern matches the value or not
You can also use match operator for this
env assert_eq(str_match("abc", "^a"), true)
env assert_eq(str_match("abc", "^a"), "abc" match "^a")
str_replace
env regex.str_replace(
attr: '& str',
pattern: 'Regex',
rep: '& str'
)
Arguments
attr: '& str'
=> original stringpattern: 'Regex'
=> Regex pattern to matchrep: '& str'
=> replacement string
Replace the occurances of the given match
env assert_eq(str_replace("abc", "^a", 2), "2bc")
env assert_eq(str_replace("abc", "[abc]", 2), "222")
str_find
env regex.str_find(attr: '& str', pattern: 'Regex')
Arguments
attr: '& str'
=> attribute to check for patternpattern: 'Regex'
=> Regex pattern to match
Find the given pattern in the value
env assert_eq(str_find("abc", "^[ab]"), "a")
str_find_all
env regex.str_find_all(attr: '& str', pattern: 'Regex')
Arguments
attr: '& str'
=> attribute to check for patternpattern: 'Regex'
=> Regex pattern to match
Find all the matches of the given pattern in the value
env assert_eq(str_find_all("abc", "[ab]"), ["a", "b"])
str_count
env regex.str_count(attr: '& str', pattern: 'Regex')
Arguments
attr: '& str'
=> attribute to check for patternpattern: 'Regex'
=> Regex pattern to match
Count the number of matches of given pattern in the string
env assert_eq(str_count("abc", "[ab]"), 2)
str_split
env regex.str_split(
attr: '& str',
pattern: 'Regex',
limit: 'Option < usize >'
)
Arguments
attr: '& str'
=> String to splitpattern: 'Regex'
=> Regex pattern to split withlimit: 'Option < usize >'
=> Limit the split to maximum number
Split the string with the given pattern
env assert_eq(str_split("abc", "^[ab]"), ["", "bc"])