Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Repeating RegExp on Same Line

Repeating RegExp on Same Line

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by WillFa   USA  (525 posts)  Bio
Date Fri 29 Aug 2008 01:51 AM (UTC)

Amended on Fri 29 Aug 2008 01:54 AM (UTC) by WillFa

Message
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.
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #1 on Fri 29 Aug 2008 02:22 AM (UTC)
Message
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.
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #2 on Fri 29 Aug 2008 08:08 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 29 Aug 2008 10:01 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,180 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.