Multiple matches on a single line

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

Multiple matches on a single line

Post by Yetzederixx »

I want to parse every word that could be a player killer: ([a-zA-Z']+)

This works fine IF their name is the first word on a line, so in the follow example Gnur's name will color and Kulek's will not:

Gnur is resting on a plush couch made of royal purple velvet.
(White Aura) Kulek is here.

I've checked the matches all box and really don't want to mess with string manipulation if I don't have to, but I'll probably have to for other reasons.
Last edited by Yetzederixx on Sat Apr 23, 2011 10:24 pm, edited 1 time in total.

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

Re: Multiple matches on a single line

Post by Vadi »

Yeah... our forums can't embed html yet. (they will if you find an addon to phpBB that allows it).

You did enable match all option? matches[] will then contain all matches (your script will be run once on it).

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

Re: Multiple matches on a single line

Post by Yetzederixx »

Well I figured out a way to grab it with the spell flags and get it to highlight by changing the pattern to: (?:\([\w ]+\) )*([a-zA-Z']+)

I really don't want to do multiple patterns on this trigger if at all possible as I'm worried about efficiency.

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

Re: Multiple matches on a single line

Post by Yetzederixx »

So I ended up going with two regex's. One to highlight the name if it's the first on the line or if it's first on the line after the spell flags, the other highlights the name if it's the last word on a line aside from punctuation. However, it will still not highlight if both of these things are true as it will only work on whichever pattern happens to match first.

For example I've colored everything red that gets colored
Central Hall of the Red Tower

[Exits: east south up down ]
A huge couch of plush, crimson velvet and silver embroidery sits here.
A fountain carved out of dark red marble trickles slowly with cold water.
(Hostile) Krys'lysk is here.

murder krys

Krys'lysk yells 'Help! I am being attacked by Kulek!'
Your magic mauls Krys'lysk.
Krys'lysk has a few scratches.

check
Kulek is here, fighting Krys'lysk.
Krys'lysk has a few scratches.


Regex 1: ([A-Z]'{0,1}[a-zA-Z]+'{0,1}[a-zA-Z]+)[?.!]{1,1}'{0,1}$
Regex 2: (?:\([a-zA-Z\s]+\) )*([A-Z]'{0,1}[a-zA-Z]+'{0,1}[a-zA-Z]+)
Code: [show] | [select all] lua
local index, clan = getIndex(matches[2])

if index ~= -1 then -- found someone
	local rf, gf, bf = getClanFgColor(clan)
	local rb, gb, bb = getClanBgColor(clan)

	selectCaptureGroup(2)
	setFgColor(rf, gf, bf)
	setBgColor(rb, gb, bb)
	deselect()
end

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

Re: Multiple matches on a single line

Post by Vadi »

Several ways to do this I think. Best one might be just to abstract this into a function and have triggers.

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

Re: Multiple matches on a single line

Post by Yetzederixx »

What I don't want to do is change the pattern to ^.*$ and then parse each line for names and then try to figure out how to either replace the names in color or rebuild each and every line with cecho.

It seems that the match all checkbox is basically doing nothing as it doesn't matter if it's checked or not it will only ever match/fire once per line.

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

Re: Multiple matches on a single line

Post by Vadi »

'match all' means multiple matches of the same pattern per line - it doesn't deal with multi-pattern triggers at all. Don't do that, why won't having 2 triggers with the same script work?

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Multiple matches on a single line

Post by Rakon »

I've tried that match all method for a colour trigger, and it does not work. IE, I've had to resort to a function adding temp triggers to highlight words.

EX:

Trigger - (All as substring)
1)hidden
2)shrouded
3)monolith

Check match all, and then check a colour.

If ALL of those words appear on the same line. Only the first one is actually matched/coloured. Is this proper? I thought it would be the OR trigger (multiline/and is not checked). Why is it not highlighting all occurances of each word?

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

Re: Multiple matches on a single line

Post by Vadi »

match all means the regex /g flag. It's not for other types of triggers or other patterns within one

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Multiple matches on a single line

Post by Rakon »

Ahh, alright. Thanks for clarifying that then.

Post Reply