strfind
• Introduced in version Finds and extracts substrings from a string. strfind() is used to match a pattern against an input string and extract all of the capture groups. The function returns an id which can be used with other functions to extract the information. The supplied pattern is a regular expression. Functions related to strfind():
getFindCount(id) getGroupCount(id) getGroup(id, matchNo, groupNo) getGroupStart(id, matchNo, groupNo) getGroupEnd(id, matchNo, groupNo) Both matchNo and groupNo start at 1, the special group number 0 returns the whole pattern match.
Groups are the regex capture groups, designated by the parts in "(" parenthesis ")". Group 1 returns the string that matches the first regex statement in (), 2 returns the second, etc. Usage strfind(str, pattern) Example
[h: id = strfind("This is a really useless test", "(\\S+)\\s+(\\S+)\\s*")] [r: getGroupCount(id)] [r: getFindCount(id)] [r: getGroup(id, 1, 1)] [r: getGroup(id, 2, 2)]
Returns:
2 3 This really
Returns:
First group "Command-20," "Command" "-20" Next group " Sleight of Hand 10," " Sleight of Hand" "10" Next group " Knowledge (Arcana) +5" " Knowledge (Arcana)" "5"
.