Match "wolf", not "werewolf"

Posted by Blixel on Sun 02 Jan 2022 03:37 AM — 3 posts, 13,726 views.

#0
In my game, when I navigate to a new room of the dungeon, I always get a line displaying the monsters that are in the room (if there are any). The line is always is this format:

M - monster, monster, monster


Naturally some monsters are much stronger than others, and some monsters can infect you. So it's important to know the name of the monster I'm going to fight before I start slashing away at it.

So I have triggers like this:

  <trigger
   enabled="y"
   group="Monster List for Auto-Killing"
   keep_evaluating="y"
   match="^M - .*?(troglodyte|magician).*$"
   regexp="y"
   send_to="12"
   sequence="111"
  >
  <send>-- HIT DAMAGE: 7 + dice(1,4)
-- MAX DAMAGE: 11

Execute("disableHitMessages")
EnableTrigger("hitMessage11", true)

if (autokill) then
  Execute ("killonemob %1")
end</send>
  </trigger>


I have different monsters activate different hitMessage# triggers based on the maximum amount of damage they can do. This all works great except when I have ambiguous monster names like "owl" and "howler", or "wolf" and "werewolf", or "gorgon" and "demogorgon". Using the wolf/werewolf as an example, I have these regex statements:

^M - .*?(wolf|troll|piercer).*$


and

^M - .*?(werewolf).*$


I want these to be 2 separate triggers because the wolf/troll/piercer monsters are of equal strength, but the werewolf is a bit tougher and can also infect me, so I can't just do a basic attack on the werewolf. The problem I'm having is that when a werewolf is in the room, my trigger tries to attack "wolf" because wereWOLF is the same as wolf as far as the regex is concerned. So I'm trying to figure out how to make it so that the first trigger will match wolf, but not match werewolf. I thought I had figured it out using the regex101 site, but once I put the regex into practice, it didn't work.

I'm having this same problem with "owl" and "howler" (2 monsters that are polar opposite on the difficulty scale). This was the regex that at first seemed to be working, but ultimately was not.

^M - ?.*?([^h](owl)|weasel|fox|frostbat|lynx|icetoad|wolverine|dervish|brigand|robber).*$


So my question is - how do I fix my regex lines to only match exact monster names?

Thanks
Amended on Sun 02 Jan 2022 03:40 AM by Blixel
Australia Forum Administrator #1
See http://gammon.com.au/regexp

In particular, you can put things that should be whole words with a \b around them, so instead of wolf you would put \bwolf\b.

You could probably put the \b around the whole group (the alternatives) rather than each one.
Amended on Sun 02 Jan 2022 06:28 AM by Nick Gammon
#2
Nick Gammon said:

See http://gammon.com.au/regexp

In particular, you can put things that should be whole words with a \b around them, so instead of wolf you would put \bwolf\b.


That works, thank you so much.


Nick Gammon said:

You could probably put the \b around the whole group (the alternatives) rather than each one.


That works and is probably even better. Thanks, I appreciate it.