How do I create an Ansi/Color Trigger to capture multiple values.

Post Reply
jieiku
Posts: 33
Joined: Fri Mar 01, 2019 1:25 pm
Contact:

How do I create an Ansi/Color Trigger to capture multiple values.

Post by jieiku » Sat Apr 20, 2019 12:40 pm

here is the output I am trying to create a Trigger for:
2019-04-20_05-51.png
2019-04-20_05-51.png (9.34 KiB) Viewed 533 times
Initially I had a trigger with a pattern like this:

Code: Select all

^You still have to kill \* (.*) \((.*)\)$

aard.qTarget = matches[2]
aard.qLocation = matches[3]
This worked fairly well in most cases, but there are some situations where it does not one I recently ran into was parenthesis being part of the room name:
2019-04-20_05-31.png
2019-04-20_05-31.png (1.59 KiB) Viewed 541 times
The outer set of parenthesis are always grey, and anything inside of them that is cyan is part of the room name, so I figured an ansi trigger would solve this.

In cMud you would specify the ansi color '%e[1;36m as part of the pattern directly into the pattern field such as:
*group-*'%e[1;36mI've rolled a 100 sided dice 1 times, the total result is: %e[1;34m(%d)%e[0m'$

Here is what I have so far:
2019-04-20_05-37.png
2019-04-20_05-37.png (37.67 KiB) Viewed 541 times

The problem is it matches the entire line, I expected multimatches[4][2] to only match the Green Mob name:
2019-04-20_05-03.png

Also I could not find the documentations or examples for creating a complex ANSI trigger like this, I was working from this as a reference: https://forums.mudlet.org/viewtopic.php?t=4771

If I can manage to get this working I would be happy to add some examples to the wiki.

jieiku
Posts: 33
Joined: Fri Mar 01, 2019 1:25 pm
Contact:

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Post by jieiku » Sat Apr 20, 2019 2:15 pm

So part of the problem was I broke the original pattern into its individual pieces.

I did this because I thought I needed to have each regex pattern following its color trigger section Thats why the opening post I have 10 lines for my patterns. It is actually much simpler, you just use the complete Regex pattern, and also use a color trigger for the parts you want to capture that match a particular color.
2019-04-20_07-08.png
2019-04-20_07-08.png (30.07 KiB) Viewed 519 times
I was able to figure out that this is how this works after discovering the function showMultimatches()
2019-04-20_07-13.png
2019-04-20_07-13.png (15.22 KiB) Viewed 519 times

jieiku
Posts: 33
Joined: Fri Mar 01, 2019 1:25 pm
Contact:

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Post by jieiku » Sat Apr 20, 2019 4:08 pm

I am now left with a question.... What if I want to mach on the grey color (The outer Parenthesis on the Location), and capture what is between?

I am now matching the grey color:
2019-04-20_09-02.png
2019-04-20_09-02.png (22.43 KiB) Viewed 511 times
I want to use a color trigger to detect which parenthesis are the grey outside parenthesis, and then capture everything in between.

That way if a Room or Area is in a different Color or multiple colors. the Trigger would still match / work, as far as I know I have only ever seen the outer parenthesis that contain this value in grey, but the value within may occasionally have color.

Is this something that is possible?
2019-04-20_09-05.png
2019-04-20_09-05.png (24.13 KiB) Viewed 511 times

User avatar
Vadi
Posts: 4674
Joined: Sat Mar 14, 2009 3:13 pm

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Post by Vadi » Sun Apr 21, 2019 4:16 am

Isn't it multimatches[3][1] ?

jieiku
Posts: 33
Joined: Fri Mar 01, 2019 1:25 pm
Contact:

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Post by jieiku » Sun Apr 21, 2019 8:04 am

In this case it is multimatches[3][1] "A catwalk overlooking the exercise yard" But it only matched because the entire room name is cyan.

Occasionally the roomname is different colors, such as cyan and red, as well as cyan, red and white. Occasionally the room is all red as well.

However the outer Parenthesis are ALWAYS grey, so if I can capture whats between them then it wont matter what color the room is.

The only solution I can think of is that a color match trigger, could also return its position in the string.

so in the above example multimatches[4][2] and multimatches[4][3] returns the outer parenthesis. If it also returned the position in the string(multimatches[1][1]) then you could determine the substring position and length between the two parenthesis.

There is likely more than one way to accomplish this use case. I get the feeling I am just overlooking a feature or something?

User avatar
Vadi
Posts: 4674
Joined: Sat Mar 14, 2009 3:13 pm

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Post by Vadi » Sun Apr 21, 2019 10:30 am

Your regex pattern multimatches[1][3] also captures what's inbetween the brackets. Have you got an example where it doesn't?

jieiku
Posts: 33
Joined: Fri Mar 01, 2019 1:25 pm
Contact:

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Post by jieiku » Sun Apr 21, 2019 12:39 pm

Yes, it has trouble when the roomname itself has parenthesis as part of the roomname, which is why i turned to the color triggers:
2019-04-20_05-31.png
2019-04-20_05-31.png (1.59 KiB) Viewed 476 times
maybe there is a way to rewrite this so that it understand to match on the outer most parenthesis?

Code: Select all

^You still have to kill \* (.*) \((.*)\)$

User avatar
Vadi
Posts: 4674
Joined: Sat Mar 14, 2009 3:13 pm

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Post by Vadi » Sun Apr 21, 2019 3:53 pm

Yep - try (.*?), see https://www.rexegg.com/regex-quantifier ... y_solution for more reading!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 14 guests