Regex issue matching.

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

Regex issue matching.

Post by AlterAeonUser »

So, as my username states, I play a mud named Alter Aeon. In this current incarnation there are now 5 classes along with "microlevels" at the higher levels (which I am).

I am fairly versed with Regex and this simply stumps me. Nothing I do seems to make any difference.
Here is the pattern I'm trying to match.
Code: [show] | [select all] lua
Class     Level  Micro     Exp Cost  Percent
------------------------------------------------------------
Mage         25   0/11     22000000   ( 88%)
Cleric       22   3/17     29000000   ( 67%)
Thief        31   0/ 5     13000000   (100%)
Warrior      31   0/ 5     13000000   (100%)
Necromancer   9   0/ 4     11000000   (100%)   <- You can level!
This is as close as I've gotten with regex pattern, I placed the pattern to make it a bit easier to see what I want to capture.
Code: [show] | [select all] lua
Necromancer   9   0/ 4     11000000   (100%)   <- You can level!
Necromancer   \d+   (\d+)/ ??(\d+)     (\d+)   \( ??(\d+)%\) .*
Ideally, I'd be able to use the same regex pattern to capture the current/total of microlevels, and the amount of xp needed for the next microlevel for all of the classes, as they are all formatted similarly to store in variables. I know I'm missing something, but I just can't figure out what it is. I think it has to do with the weird spacing of the numbers for the total micro and percent, but I fail to see any other problem, nor a way to correct any mistakes I've made.
If additional info is needed, will gladly offer. Thanks in advance.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Regex issue matching.

Post by Jor'Mox »

I would try this as a pattern:
^(\w+)\s+(\d+)\s+(\d+)/\s*(\d+)\s+(\d+)\s+\((\d+)%\)\s*$

That should avoid all the spacing problems, and work for any class name.

Oh. And if the you can level bit is actually part of what you are trying to match, or on the same line, you can just take off the $ at the end. I wasn't sure if that was a comment or not.
Last edited by Jor'Mox on Wed Sep 04, 2013 2:33 am, edited 1 time in total.

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

Re: Regex issue matching.

Post by AlterAeonUser »

Well, yes, that would, except I'd need different captures for each class, I don't particularly desire making a huge for table to check what class it is. I will try and give it a shot tho. Thanks!

Edit: Only captures the Thief line.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Regex issue matching.

Post by Jor'Mox »

Yes, you need to know what class it is. But since you are capturing the class name, that is easy information to get. What are you trying to do with this info? Maybe I can come up with something better than "a huge for table".

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Regex issue matching.

Post by Jor'Mox »

Oh. I forgot to add the optional space inside the parens for the percent. Just add in \s* right after the open paren and it should get them all.

Like this:
^(\w+)\s+(\d+)\s+(\d+)/\s*(\d+)\s+(\d+)\s+\(\s*(\d+)%\)\s*$

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

Re: Regex issue matching.

Post by AlterAeonUser »

This is what I found works:

Mage\s+\d+\s+(\d+)/\s*(\d+)\s+(\d+)\s+(\(\s*\d+%\))

It will highlight only the capture groups I want for the Mage class. I will switch Mage out with the other classes.

Thank you very much for your help! If I could give you internet points I would.

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

Re: Regex issue matching.

Post by AlterAeonUser »

Jor'Mox wrote:Yes, you need to know what class it is. But since you are capturing the class name, that is easy information to get. What are you trying to do with this info? Maybe I can come up with something better than "a huge for table".
I want to put each class info in variables to calculate how much exp I need to get the micro, how much I need total and to be able to show those figures to clan\group mates and on channels.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Regex issue matching.

Post by Jor'Mox »

If you capture everything including the class name, you can create a table for quick and easy access to the info. I would do most stuff in a separate script via a function (because I don't like doing serious coding in triggers, but that is just me).

Something like this would work.
Code: [show] | [select all] lua
expTable = {}
function storeExpInfo(class, num1, num2, num3, ...) -- I don't know what all the numbers mean or how many you care about. So adjust the arguments and argument names as suits you
   expTable[class] = {percent = num1, total = num2, level = num3}
end
Obviously you would assign sensible names to the different values, but the. You could get any of that info like this:
expTable["Mage"].level
Or whatever other values you stored. No searching necessary.

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

Re: Regex issue matching.

Post by AlterAeonUser »

So, after returning to this post and attempting to use your regex pattern, I realized that your pattern will only capture the first line, Mage. It will not capture the Cleric - Necromancer classes. Thoughts?

phasma
Posts: 191
Joined: Sat Aug 03, 2013 7:00 pm
Discord: phasma#4694

Re: Regex issue matching.

Post by phasma »

It will actually continue capturing subsequent lines, treating them as separate matches.

Post Reply