Repeating RegExp on Same Line

Posted by WillFa on Fri 29 Aug 2008 01:51 AM — 4 posts, 12,663 views.

USA #0
The mud output is:
Syntax: train <skill>
Current Skill Levels:
 Alacrity        : 10/10(-)            Harmony         : 27/50(95790)      
 Spellcraft      : 30/50(700000)       Rhythm          : 30/46(77750)      
 Playing         : 21/21(-)            Singing         : 30/30(-)          
 Melee           : 30/30(-)            Dodge           : 24/24(-)          
 Mana            : 40/40(-)            Power           : 18/30(187000)     
 Knowledge       : 30/80(42500)      



The Trigger is:
<triggers>
  <trigger
   custom_colour="17"
   colour_change_type="2"
   enabled="y"
   keep_evaluating="y"
   match=" (?'Name'\w+)\s+: (?P&lt;Current&gt;\d+)\/(?P&lt;Max&gt;\d+)\((?P&lt;Cost&gt;[0-9,-]+)\)"
   regexp="y"
   repeat="y"
   script="foo"
   send_to="12"
   sequence="100"
   other_back_colour="dimgray"
  >
  <send>print("%&lt;Name&gt;", "%&lt;Current&gt;", "%&lt;Max&gt;", "%&lt;Cost&gt;")

function foo (t,l,w) for k,v in pairs(w) do Tell(k, " ", v, "   ") end Note("") end</send>
  </trigger>
</triggers>

function foo's definition is repeated in the send for convenience sake.

What you see: the print that's directly in the send body prints out the first column's captured information. The w table in the foo function contains the second column's captured information.

I would expect a "global" PCRE to fire the send body and script call for each match; not half on the first and the other half on the second.
Amended on Fri 29 Aug 2008 01:54 AM by WillFa
Netherlands #1
Short but simple answer: repeat="y" only affects the recolouring information in the trigger. For example, when you have the word 'merchant', you can make a regexp trigger on '\bmerchants?\b', put repeat="y" and recolor it... and have a sentence like "There is a merchant here and a few more merchants over there." colour both instances of the merchant(s) word.

The script only fires once by design. Something I personally don't like too much, but it is how it is. Best you can do is have a trigger that works, omit from output and Note() your custom output manually.
USA #2
Shouldn't the script behave consistently?

Scripts in the Send: field see the first match. The script called in the script name field sees the last match.
I have not tested what happens with three or more matches on a line.

"Repeat on same line" is only valid for regular expressions, except captured portions of the regular expression not behaving like regular expressions isn't a bug?

I have a workaround:

function foo (trig,line,wilds) 
for Name,Current,Max,Cost in line:gmatch(" (%w+)%s+: (%d+)%/(%d+)%(([%d,-]+)%)") 
do print(Name,Current,Max,Cost) 
end 
end

But feeding the triggered line through Lua's regex engine a second time to get the global matching functionality because "repeat on same line" doesn't actually repeat the regular expression on the same line, seems silly. :)

(kinda irrelevant, but I'm not just reworking the output, I'm trying to capture data into tables. Just using print() to illustrate the issue)

as an aside, where's the code's repository?
Australia Forum Administrator #3
A reasonably up-to-date version is at:

http://www.gammon.com.au/files/mushclient/src/mushclient_4.30_src.tgz

Quote:

But feeding the triggered line through Lua's regex engine a second time to get the global matching functionality because "repeat on same line" doesn't actually repeat the regular expression on the same line, seems silly. :)


There are two aspects to this:

  • Changing the behaviour now, however much it might benefit some scripts, and whatever the merits of the original design decision, is likely to break a lot of existing scripts.
  • Lua's regexp is quite fast - if not faster than the PCRE one in many cases. I don't see a huge difference between calling the internal PCRE regexp handler multiple times, and using Lua's regexp if needed to pull out multiple things from one line.