The AcctStart trigger:
has a pattern of "^Account ++Amount ++$"
Which means find From the start of line("^") "Account" plus one or more spaces (" "), "atomically" (greedily grab all the spaces, and don't bother rechecking if fewer spaces will match the pattern) ("++") followed by "Amount" and atomically grabbed spaces (" ++") until the end of line ("$").
The Send is being sent to the Scripting engine specified in the Send To field, and it sets a variable (scripting only, it's not saved) to an empty table. -> " Accts = {} "
the AcctGrab trigger:
has a pattern of "^(\d{5} ++\d+ ++$", which is, start of line ("^"), capturing 5 digits as the named parameter AcctNum, ("(?P<AcctNum>\d{5})"), atomic spaces again (" ++"), and a series of any numbers ("\d+"), and an atomic space grab again (" ++"), and then end of line ("$")
It's script set's the Table ("Acct") value, at index size of the table + 1 ("[#Accts + 1]"), equal to (" = "), The named capture parameter (" %<AcctNum>" )
AcctGrab will fire on every line that fits this format. If your mud sends something like:
Account Amount
12345 100000
98765 10
Movement To Next Lvl
10725 175324
The Accts table will end up containing:
Accts[1] = 12345
Accts[2] = 98765
Accts[3] = 10725
So that's why I recommended EnableTrigger("AcctGrab", true) during AcctStart, and disabling it in your prompt or a line that concludes the account listing.
You don't need to use non-capturing groups for spaces ("(?: +)"), the regexp engine doesn't treat a space as a delimiter or anything. " +" is just as valid.
In your original pattern, It'd only match the header line and the first line. To match additional account lines, you'd need 2 triggers.
((If you use captured parameters directly in the send to field, like this, be aware that MushClient does the capture substitution before sending the code to the Lua engine to be compiled. So the source that Lua evaluates ends up being:
Pattern: (%?P<Named>\d+)
Send To: Scripting
Send: foo = %<named>
Sample Line: " 500 "
Effective source: foo = 500
(this is fine.)
Pattern: (%?P<Named>\w+)
Send To: Scripting
Send: foo = %<named>
Sample Line: " Bob "
Effective source: foo = Bob
(this is ends up looking to set foo to a variable named Bob. Probably not what you want.)
Pattern: (%?P<Named>\d+)
Send To: Scripting
Send: foo = "%<named>"
Sample Line: " Bob "
Effective source: foo = "Bob"
(this is probably the result you want.)
|