Page 1 of 1

Help capturing multiple words into single variable, then returning them with hyphens?

Posted: Wed Aug 10, 2022 4:25 pm
by Bigglesbee
Hey guys, still can't figure it out after reading a lot of forum posts and documentation.

The phrase that triggers it would look like: (name) DISARMS your (weapon)! However, the (weapon) could be any number of words, like maybe "small sharp dagger". Due to the way the MUD works, you'd want to get all keywords in your return commands, so you'd want: wield small-sharp-dagger.

Instead of manually change the trigger whenever I have a new weapon, I'd want to be able to capture the full weapon name of whatever I happen to be using, then return the full name with the hyphens connection each keyword in the name. I can get it working with single words (no hyphen, only need to capture one word), but just can't figure it out for multiple words in a sentence, much less returning those words attached with hyphens.

Here's the single-word trigger I have:

Code: Select all

^(?<disarmer>\w+) DISARMS your ('?<weapon>\w+')!
Which then leads into

Code: Select all

send("get "..matches.weapon)
send("wield "..matches.weapon)
Is there any way to do this? Thanks in advance.

Re: Help capturing multiple words into single variable, then returning them with hyphens?

Posted: Wed Aug 10, 2022 10:56 pm
by demonnic
Change the \w+ in the pattern for getting a single word weapon to .+ to capture everything there.

Code: Select all

^(?<disarmer>\w+) DISARMS your ('?<weapon>.+')!
then you can use string.gsub to change all the spaces into dashes and send the commands.
Code: [show] | [select all] lua
local weapon = matches.weapon:gsub(" ", "-")
sendAll("get " .. weapon, "wield " .. weapon)

Re: Help capturing multiple words into single variable, then returning them with hyphens?

Posted: Thu Aug 18, 2022 8:10 am
by Bigglesbee
Thanks, I'll give it a shot!