[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Multiline trigger help?

Multiline trigger help?

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


Posted by Kovarid   (15 posts)  [Biography] bio
Date Fri 20 Jun 2014 02:02 PM (UTC)
Message
I am trying to make a trigger to grab data from a status report in TrekMUSH; There are a few commands that have very similar output so I need to do a multiline to verify this is the one I want.

Here is part of the output. (There are more lines, but this chunk is really what I need.)


--[Helm Status Report]---------------------------------------------------------
  Galactic X Y Z:       -9457.649          56.074         -79.870
  Relative X Y Z:         120.295         -63.926          10.130
  Destinat X Y Z:        -106.900          -1.900         -50.100
-------------------------------------------------------------------------------


I need to be able to grab the coordinates that follow "Galactic XYZ:", but the number of spaces varies depending on the numbers, and the trigger doesn't seem to catch it.

I -thought- just use a * to grab it all, and then use a script to trim what I need, but the wildcard matching doesn't ignore whitepsace.

A secondary question, but highly related to this, is if there is a way to ignore arbitrary whitespace in a trigger or alias and only return non whitespace?
E.g.

cf 1     5    6
and
cf 1 5 6

Would match the same trigger/alias and just ignore the extra whitespace.

I'd really appreciate some assistance with this.
Currently what I do is, pass the whole match string to a lua function that strips whitespace and converts the string into a table that I can parse, but that feels very hackish to me.
[Go to top] top

Posted by Kovarid   (15 posts)  [Biography] bio
Date Reply #1 on Fri 20 Jun 2014 02:53 PM (UTC)

Amended on Fri 20 Jun 2014 03:03 PM (UTC) by Kovarid

Message
This is what I am trying to use currently, to make the line match.. Now if I can integrate this into a multiline, I'm golden. :)




^\s*Galactic X Y Z\:\s*([+-]?\d*\.\d+)(?![-+0-9\.])\s*([+-]?\d*\.\d+)(?![-+0-9\.])\s*([+-]?\d*\.\d+)(?![-+0-9\.])$


I'm still working on learning regexp, BTW.
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 20 Jun 2014 08:35 PM (UTC)

Amended on Fri 20 Jun 2014 08:36 PM (UTC) by Nick Gammon

Message
I don't quite follow your trigger based on your test data. You have 3 groups of numbers arriving but the trigger seems to be looking for six of them.

You can simplify the trigger by doing a "subroutine call" because all three sets of numbers look the same. For example:


<triggers>
  <trigger
   enabled="y"
   match="^\s*Galactic X Y Z\:\s+([+-]?\d*\.\d+)\s+((?1))\s+((?1))$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Matched!
Wildcard 1 = %1
Wildcard 2 = %2
Wildcard 3 = %3

</send>
  </trigger>
</triggers>


Matching on your test data I get:


Matched!
Wildcard 1 = -9457.649
Wildcard 2 = 56.074
Wildcard 3 = -79.870


Template:regexp Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.


Quote:

I need to be able to grab the coordinates that follow "Galactic XYZ:", but the number of spaces varies depending on the numbers, and the trigger doesn't seem to catch it.


It worked OK for me.

Quote:

Now if I can integrate this into a multiline, I'm golden. :)


Why bother? Why not three similar triggers? Or even one like this:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^\s*(Galactic|Relative|Destinat) X Y Z\:\s+([+-]?\d*\.\d+)\s+((?2))\s+((?2))$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Matched!
Wildcard 1 = %1
Wildcard 2 = %2
Wildcard 3 = %3
Wildcard 4 = %4

</send>
  </trigger>
</triggers>


On your test data:


--[Helm Status Report]---------------------------------------------------------
  Galactic X Y Z:       -9457.649          56.074         -79.870
Matched!
Wildcard 1 = Galactic
Wildcard 2 = -9457.649
Wildcard 3 = 56.074
Wildcard 4 = -79.870

  Relative X Y Z:         120.295         -63.926          10.130
Matched!
Wildcard 1 = Relative
Wildcard 2 = 120.295
Wildcard 3 = -63.926
Wildcard 4 = 10.130

  Destinat X Y Z:        -106.900          -1.900         -50.100
Matched!
Wildcard 1 = Destinat
Wildcard 2 = -106.900
Wildcard 3 = -1.900
Wildcard 4 = -50.100

-------------------------------------------------------------------------------


In your script you can save the appropriate figures based on wildcard #1.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 20 Jun 2014 08:47 PM (UTC)
Message
Quote:

There are a few commands that have very similar output so I need to do a multiline to verify this is the one I want.


If you really want a multiline trigger, this seems to work:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   lines_to_match="3"
   match="\A\s+Galactic( X Y Z\:\s+)([+-]?\d*\.\d+)\s+((?2))\s+((?2))\n\s+Relative(?1)((?2))\s+((?2))\s+((?2))\n\s+Destinat(?1)((?2))\s+((?2))\s+((?2))\Z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Matched!
Wildcard 1 = %1
Wildcard 2 = %2
Wildcard 3 = %3
Wildcard 4 = %4
Wildcard 5 = %5
Wildcard 6 = %6
Wildcard 7 = %7
Wildcard 8 = %8
Wildcard 9 = %9
Wildcard 10 = %&lt;10&gt;</send>
  </trigger>
</triggers>


Testing it:


--[Helm Status Report]---------------------------------------------------------
  Galactic X Y Z:       -9457.649          56.074         -79.870
  Relative X Y Z:         120.295         -63.926          10.130
  Destinat X Y Z:        -106.900          -1.900         -50.100
Matched!
Wildcard 1 =  X Y Z:       
Wildcard 2 = -9457.649
Wildcard 3 = 56.074
Wildcard 4 = -79.870
Wildcard 5 = 120.295
Wildcard 6 = -63.926
Wildcard 7 = 10.130
Wildcard 8 = -106.900
Wildcard 9 = -1.900
Wildcard 10 = -50.100
-------------------------------------------------------------------------------

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Kovarid   (15 posts)  [Biography] bio
Date Reply #4 on Sat 21 Jun 2014 11:22 AM (UTC)

Amended on Sat 21 Jun 2014 11:24 AM (UTC) by Kovarid

Message
Ah thank you Nick!

The reason I need it to be multiline is because there are other reports that show the exact same 'Galactic XYZ:' but are not our location but another ship's location (if we scan it).

That's why it needs to verify that it comes from the "Helm Status Report"
The Relative and Destination XYZ are irrelevent.

I was using a text2re website to help me generate that trigger I posted earlier, it seemed to work but not 100%. I will try yours.

Wait until you see this plugin. I'm already up over 1200 lines in the script. ;) (lots of vector math and such)
[Go to top] top

Posted by Nick Gammon   Australia  (22,985 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 21 Jun 2014 09:09 PM (UTC)

Amended on Sat 21 Jun 2014 09:11 PM (UTC) by Nick Gammon

Message
Well in that case you want something like this, assuming I counted the hyphens properly:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="\A-{2}\[Helm Status Report\]-{57}\n\s*Galactic X Y Z\:\s+([+-]?\d*\.\d+)\s+((?1))\s+((?1))\Z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>
Matched!
Wildcard 1 = %1
Wildcard 2 = %2
Wildcard 3 = %3
</send>
  </trigger>
</triggers>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


16,694 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]