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

Post Reply
Bigglesbee
Posts: 24
Joined: Wed Aug 10, 2022 4:13 pm

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

Post 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.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

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

Post 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)

Bigglesbee
Posts: 24
Joined: Wed Aug 10, 2022 4:13 pm

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

Post by Bigglesbee »

Thanks, I'll give it a shot!

Post Reply