Bracket capture for triggers

Posted by Xandler on Tue 02 Jul 2024 06:51 PM — 10 posts, 14,956 views.

#0
Sorry if this was posted somewhere else and I didn't see it, I've been browsing the forums looking for similar but couldn't find any applicable. Long story short, I play on a mud that sometimes has brackets ([]) around the text and I'm trying to capture that text and send it to a variable to add it up ie [Double Points] You have gained x [*clan] clan points for doing y.

What I currently have is:

<triggers>
  <trigger
   enabled="y"
   group="CP_Count"
   match="^([Double Clan Points] )?(\w+) (have|has) earned (\d+) [\*clan] clan point from (your|their) valiant effort in slaying (.+)!?"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>CP = tonumber (GetVariable ("CP")) or 0
CP = CP + %3
SetVariable ("CP", CP)</send>
  </trigger>
</triggers>

Do note that this match was given to me by someone using a different client (that uses LUA) but it's still LUA based
I've been testing that with the manual test trigger function in mushclient and it just stays at 0 matches, I'm at a loss on how to make it work. Is there anything simple I'm just not seeing?
Australia Forum Administrator #1
To match round or square brackets in a regular expression, just put a backslash in front of it, so for example \[foo\] would match [foo].
Amended on Tue 02 Jul 2024 08:45 PM by Nick Gammon
#2
Nick Gammon said:

To match round or square brackets in a regular expression, just put a backslash in front of it, so for example \[foo\] would match [foo].


So, in theory it should be

^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*clan\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$


But that isn't matching either?
Amended on Wed 03 Jul 2024 02:16 AM by Xandler
Australia Forum Administrator #3

 ie [Double Points] You have gained x [*clan] clan points for doing y.


OK, you need to show exactly what arrives from the MUD.


Your trigger was "[Double Clan Points]" so that is not the same as [Double Points] is it?

Then you say "for doing y" which is not the same as "from (your|their) valiant effort in slaying" is it?

You may be paraphrasing, but in order to help we need to see the exact message coming from the MUD.
#4
Nick Gammon said:


 ie [Double Points] You have gained x [*clan] clan points for doing y.


OK, you need to show exactly what arrives from the MUD.


Your trigger was "[Double Clan Points]" so that is not the same as [Double Points] is it?

Then you say "for doing y" which is not the same as "from (your|their) valiant effort in slaying" is it?

You may be paraphrasing, but in order to help we need to see the exact message coming from the MUD.


The exact match is:

^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*SDS\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$


I've tried numerous times "testing" it with the test trigger for mushclient and unable to get it to have a match.
Amended on Thu 04 Jul 2024 01:58 AM by Xandler
Australia Forum Administrator #5
OK, that's the trigger. Now post the message from the MUD that it is supposed to match, but is not matching.
#6

[Double Clan Points] You have earned 2 [*SDS] clan point from your valiant effort in slaying Lootie the Living Loot Box!

Supposed to match that (for example) but with You, the actual number, point, your, and the *mob name* substituted out like in the trigger, if that makes sense.
USA Global Moderator #7
The regular expression
^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*SDS\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$

does match the line
Quote:
[Double Clan Points] You have earned 2 [*SDS] clan point from your valiant effort in slaying Lootie the Living Loot Box!


I tested it, and sending print("%1", "%2", "%3", "%4", "%5", "%6") did the right thing.
Amended on Thu 04 Jul 2024 05:42 PM by Fiendish
#8
Fiendish said:

The regular expression
^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*SDS\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$

does match the line
Quote:
[Double Clan Points] You have earned 2 [*SDS] clan point from your valiant effort in slaying Lootie the Living Loot Box!


I tested it, and sending print("%1", "%2", "%3", "%4", "%5", "%6") did the right thing.


That is really strange because I can't get it to "match" on the mud at all but this will match:


<triggers>
  <trigger
   enabled="y"
   group="CP_Count"
   match="^(\[Double Clan Points\] )?(\w+) (have|has) earned (\d+) [\*SDS] clan point from (your|their) valiant effort in slaying (.+)!?"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>CP = tonumber (GetVariable ("CP")) or 0
CP = CP + %4
SetVariable ("CP", CP)</send>
  </trigger>
</triggers>
Australia Forum Administrator #9
You omitted the final $ from the regular expression so maybe there is a space at the end of the line from the MUD.