Odd pattern to regex match

Post Reply
AlterAeonUser
Posts: 26
Joined: Sun Sep 01, 2013 11:08 pm

Odd pattern to regex match

Post by AlterAeonUser »

So, one of the commands allows you to see how close to you're next micro level (partial levels, instead of one whole xp amount to level, you have x/n micro levels) Well, I made a trigger to match on the first pattern, then realized today that it won't match on the second.
You need 22000000 experience to level Mage to 26 and have 20247518 experience. (92%)
You need 13000000 experience to micro level Warrior to 31:1 and have 20247518 experience. (100%)
Here is my original pattern that works for the first and consecutive after I get my first 31 micro level:
You need (\d+) experience to level (\w+) to (\d+) and have (\d+) experience.
That will match what I need it to match, but won't match the 31:1. I tried to use this:
You need (\d+) experience to level (\w+) to (\d+(:1)?) and have (\d+) experience.
But that won't match the 31:1 either. My bigger problem is, once I get that first micro, the :1 goes away. (that's why I thought doing the (:1)? would work, but it doesn't.

Perhaps somebody a bit more proficient with regex could point out my error and help me better my Regex skills?

Tagon
Posts: 24
Joined: Thu Sep 19, 2013 8:38 pm

Re: Odd pattern to regex match

Post by Tagon »

try ([0-9\:]+)

I think... should be the set of digits and the colon as one match, will for with or without the colon.

AlterAeonUser
Posts: 26
Joined: Sun Sep 01, 2013 11:08 pm

Re: Odd pattern to regex match

Post by AlterAeonUser »

The :1 will be removed once I get the micro. so thats why I thought the (:1)? would work, because it's not always there.

Also, I did realize that the 31:1 line has the additional word "micro", but doing (micro)? { or even (\w+)? } screws up the pattern also...

AlterAeonUser
Posts: 26
Joined: Sun Sep 01, 2013 11:08 pm

Re: Odd pattern to regex match

Post by AlterAeonUser »

You need (\d+) experience to( micro)? level (\w+) to (\d+)(:1)? and have (\d+) experience.
Pattern that works. Thank you Tagon for your assistance. Sometimes I just need to see it in a different context (possibly with a different font) to see my errors.

Tagon
Posts: 24
Joined: Thu Sep 19, 2013 8:38 pm

Re: Odd pattern to regex match

Post by Tagon »

Code: [show] | [select all] lua
^You need (\d+) experience to .*level (\w+) to ([0-9:]+) and have (\d+) experience. \((\d+)\%\)$
Will give you

matches[2] = experience needed
matches[3] = profession
matches[4] = level (either a number, or a number:number)
matches[5] = current exp
matches[6] = % level

you could then test whether matches[4] contained the substring ":" and use that to handle whether you are dealing with micro levels or not, since you have to split it anyway. I'm not sure if my method is a bit rustic but it works:
Code: [show] | [select all] lua
first = true
for value in string.gmatch(matches[4],"\d+") do
	if not first then 
		microlevel=value 
		break
	else
		level=value
		first=false
	end
end

AlterAeonUser
Posts: 26
Joined: Sun Sep 01, 2013 11:08 pm

Re: Odd pattern to regex match

Post by AlterAeonUser »

You're method is fine, but needlessly uses extra stuff for checking for the :. The : only appears if I don't have any microlevels in a particular class above 31. This mud is multiclass to level 40 (i do believe) and you have micro levels past certain thresholds. So doing a check for the : is only needed for one instance, and my pattern will correctly capture everything I needed it to check.

Again, thank you for the assistance, I'm sure your help will come in handy at some point when I'm doing bigger things.

Post Reply