Multiple matches on a single line

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Multiple matches on a single line

Post by Yetzederixx »

I did change it to two triggers, one for beginning of line and one for end of line, I just wanted to do it with one is all.

Then I have no clue what the match all thing is and/or is for evidently.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Multiple matches on a single line

Post by Vadi »

Does the tooltip explain it to you? I'll rephase it if it's not good enough

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Multiple matches on a single line

Post by Yetzederixx »

I've had it checked through the entire process. From what I could find of the /g option it returns an array, table in lua I'd imagine, so do I access it matches[2], matches[3], etc or is it in a multimatches? Guess that's where I'm confused.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Multiple matches on a single line

Post by Vadi »

It's matches[n+2..], yes. Just try display(matches)

But it's not applicable to your case. That option is for the regex patterns themselves, not the overall multi-pattern trigger.

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Multiple matches on a single line

Post by Yetzederixx »

Ok, got this far with some experimenting.

Reduced it to a single regex again and then just display(matches) to see what I got.

Code: Select all

Diamante Ka'tath walks in.
table {
  1: 'Diamante'
  2: 'Diamante'
  3: 'Ka'tath'
  4: 'Ka'tath'
}
I can probably use similar code to what I already have just put it into a loop to select and color the replacements, just have to remember to reset them back to defaults. Is there a get the default fore/background color from settings?

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Multiple matches on a single line

Post by Yetzederixx »

Alright, aside from how to capture a name in the plural (my MUD allows single quotes in player names) I've got it to work with a single regex.

Regex: ([A-Z]'{0,1}[a-zA-Z]+'{0,1}[a-zA-Z]+)
Code: [show] | [select all] lua
local i = 2

while i <= #matches do
	local isClanner, clan = getIndex(matches[i]) -- personal fn to see if they're in database/table 

	if isClanner then -- found someone
		local rf, gf, bf = getClanFgColor(clan) -- both of these just return r, g, b values based on clan
		local rb, gb, bb = getClanBgColor(clan)

		selectCaptureGroup(i)
		setFgColor(rf, gf, bf)
		setBgColor(rb, gb, bb)
		deselect()
	end
	
	i = i + 2 -- it's double capturing so we only need the evens
end
Any ideas on how to get the regex NOT to match the 's in: Krys'lysk's freezing bite wounds you.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Multiple matches on a single line

Post by Vadi »

If someone won't be able to help you with a trigger, this will sanitize this for you - :gsub("'s$", "")

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Multiple matches on a single line

Post by Yetzederixx »

Reading string.gsub() now, thanks for all your help. I didn't understand that it was returning more elements in the matches array.

Any idea why it's doubling up in the matches table though?

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Multiple matches on a single line

Post by Yetzederixx »

by changing a line to add in the string.gsub() fn it's fixed!!!!
Code: [show] | [select all] lua
local isClanner, clan = getIndex(string.gsub(matches[i], "'s$", ""))

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Multiple matches on a single line

Post by Heiko »

It's not doubling up matches, it's just doing the usual practice:
1. complete first match 2. first capture group 3. second cap group ... n+1. complete second match on the line, n+2. first cap group of the second match etc.

So if you enable match all, the trigger engine fills matches[] with all matches and all capture groups of this lline and THEN runs the script.

Post Reply