Targetting help

Share your scripts and packages with other Mudlet users.
chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

Duugan wrote:Any idea how to get a trigger for HP with <Name><###/### HP?
Perl regex pattern: ^<\w+><(\d+)/(\d+) HP$

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

chrio wrote:
Duugan wrote:Any idea how to get a trigger for HP with <Name><###/### HP?
Perl regex pattern: ^<\w+><(\d+)/(\d+) HP$
Interesting. In this instance, the \w+ doesn't need to be in parenthesis? I tried something similar, but had it in parenthesis and it wasn't working. I imagine that's why?

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Targetting help

Post by SlySven »

As you are not interested in capturing whatever \w+ matches ("Name") you don't put it in parenthesise...! If you did you'd have to change the indexes for matches[...] in the script.

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

SlySven wrote:As you are not interested in capturing whatever \w+ matches ("Name") you don't put it in parenthesise...! If you did you'd have to change the indexes for matches[...] in the script.
For testing purposes, I was just changing the text color with the script. The <> were giving me issues, but I'll play with it more when I have time. I never got far enough to have issues with the matches. :)

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Targetting help

Post by SlySven »

Oh, I just had a play on https://regex101.com/ and found that the '/' between the numbers needs escaping with a preceding '\'... other wise I was wondering whether there was a space in the strings you are trying to match between the <Name> and the 123/456 numbers - "\w" matches any of: "a-zA-Z0-9_" but not, of course any white-space. Finally (literally!), the '$' matches the end of the string so if the input is actually of the form "<Someone><1/100 HP something else" the " something else" including the space after the "HP", will prevent a match.

chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

SlySven wrote:Oh, I just had a play on https://regex101.com/ and found that the '/' between the numbers needs escaping with a preceding '\'...
Just to avoid some confusion here, while true on the site above, escaping forward slashes is not needed with the regex version used in mudlet, but it's good to keep in mind when using regular expressions elsewhere (like in perl scripts).

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

I wasn't using the $ because there is indeed more after the HP. In order to capture the 123/456 though, it requires a perl string, right? Is that why I had to use (.*) because it should have been (\d+)/\(\d+) HP?

chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

Duugan wrote:I wasn't using the $ because there is indeed more after the HP.
Ah, ok
Duugan wrote:In order to capture the 123/456 though, it requires a perl string, right?
Yes
Duugan wrote: Is that why I had to use (.*) because it should have been (\d+)/\(\d+) HP?
With (.*) you mean the parenthesis around \d+ patterns, right? Yes, but if you don't care about the maxhp you only need parenthesis around the first \d+.

Duugan
Posts: 25
Joined: Fri Aug 26, 2016 4:00 am

Re: Targetting help

Post by Duugan »

It's been a while, so I don't remember every issue I had...
I know originally I had [Name] #/# HP and it wouldn't read the number with anything I tried. I changed it to .* and it got the name and number, so I moved the name elsewhere and left the code alone.
I suppose in hindsight, I needed an escape?
\[\w+\] (\d+)\/(d+) HP as a perl regex...?

chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Re: Targetting help

Post by chrio »

yes, \[\w+\]... would have worked to match the name (except the last \ ended up in the wrong place, but that's a typo, you got the idea right).

Or if you don't intend to use it in a variable or on have the trigger on different chars, just write it \[MyNameHere\]. Not saying it's better, just pointing out alternatives. I would have done it your way.

Post Reply