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.
Entire forum
➜ MUSHclient
➜ General
➜ Multiline trigger help?
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kovarid
(15 posts) 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.
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. | Top |
|
Posted by
| Kovarid
(15 posts) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) 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
|
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 | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) 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 = %<10></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 | Top |
|
Posted by
| Kovarid
(15 posts) 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) | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) 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 | 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.
18,385 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top