Finds and extracts substrings from a string. strfind() s 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()
Both Group numbers and find numbers start at 1, the special group number 0 returns the whole pattern match. 'Groups' are the regex parts in "(" parenthesis ")" so 1 returns the string that matches the first regex statement in () 2 returns the second, etc.
strfind(str, pattern)
[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 This is
A slightly more usefull and advanced example
[h:id = strfind("Command-20, Sleight of Hand 10, Knowledge (Arcana) +5", "([^,]*?)\\s?([-+]?\\d+)(,|\$)")]
<b>First group</b><br>
[r,count(getFindCount(id), "<b>Next group</b><br>"), code: { "[r:getGroup(id, roll.count+1, 0)]" <br> "[r:getGroup(id, roll.count+1, 1)]" <br> "[r:getGroup(id, roll.count+1, 2)]" <br>} ]
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"