Perl regex pattern: ^<\w+><(\d+)/(\d+) HP$Duugan wrote:Any idea how to get a trigger for HP with <Name><###/### HP?
Targetting help
Re: Targetting help
Re: Targetting help
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?chrio wrote:Perl regex pattern: ^<\w+><(\d+)/(\d+) HP$Duugan wrote:Any idea how to get a trigger for HP with <Name><###/### HP?
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: Targetting help
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
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.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.
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: Targetting help
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
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).SlySven wrote:Oh, I just had a play on https://regex101.com/ and found that the '/' between the numbers needs escaping with a preceding '\'...
Re: Targetting help
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
Ah, okDuugan wrote:I wasn't using the $ because there is indeed more after the HP.
YesDuugan wrote:In order to capture the 123/456 though, it requires a perl string, right?
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 wrote: Is that why I had to use (.*) because it should have been (\d+)/\(\d+) HP?
Re: Targetting help
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...?
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
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.
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.