Page 4 of 5

Re: Targetting help

Posted: Tue Sep 06, 2016 7:35 am
by chrio
Duugan wrote:Any idea how to get a trigger for HP with <Name><###/### HP?
Perl regex pattern: ^<\w+><(\d+)/(\d+) HP$

Re: Targetting help

Posted: Wed Sep 07, 2016 7:21 am
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?

Re: Targetting help

Posted: Wed Sep 07, 2016 2:56 pm
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.

Re: Targetting help

Posted: Wed Sep 07, 2016 3:00 pm
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. :)

Re: Targetting help

Posted: Wed Sep 07, 2016 3:44 pm
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.

Re: Targetting help

Posted: Wed Sep 07, 2016 5:14 pm
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).

Re: Targetting help

Posted: Wed Sep 07, 2016 10:04 pm
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?

Re: Targetting help

Posted: Thu Sep 08, 2016 7:46 am
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+.

Re: Targetting help

Posted: Thu Sep 08, 2016 10:40 am
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...?

Re: Targetting help

Posted: Thu Sep 08, 2016 11:27 am
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.