Referencing Named Groups in RegEX

Post Reply
nerane
Posts: 3
Joined: Sun Aug 14, 2011 4:52 am

Referencing Named Groups in RegEX

Post by nerane »

I am working with the following Trigger expression.

Code: Select all

^(?:\[>> TURN <<\] )(?:Nerane)(?: *)(?:\[)(?<HealthPct>\d*)(?:%)(?: *)(?<CurrentHP>\d*)(?:/ *)(?<MaxHP>\d*)(?: *EN *)(?<Energy>\d*)(?:\])$
How would i reference this from the lua, something like the below:
Code: [show] | [select all] lua
_maxHP = tonumber( Matches('MaxHP') )
Any help here would be apprecicated.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Referencing Named Groups in RegEX

Post by tsuujin »

Unless something has changed that I'm unware of, Heiko has stated that he has no intention of honoring named references. You'll have to deal with them numerically.

nerane
Posts: 3
Joined: Sun Aug 14, 2011 4:52 am

Re: Referencing Named Groups in RegEX

Post by nerane »

That seems a little harsh. It should not be that hard. If he pointed me at the code, I might even be able to get it up and running. Im soon looking to do some pretty serious mutli-line captures that numerically would be a nightmare.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Referencing Named Groups in RegEX

Post by tsuujin »

Honestly, I've gotten used to it. I build regex patterns into my personal system that incorporate twenty or so backreferences, and just comment the regex in the code. It works out fine.

I believe Heiko outright refused named references when I asked for them on the basis that it's not needed and would slow down the parsing.

nerane
Posts: 3
Joined: Sun Aug 14, 2011 4:52 am

Re: Referencing Named Groups in RegEX

Post by nerane »

I understand that there would be some impact to performance, but readability has value as well. I know this from working on projects with thousands or millions of lines of code. hell we define constants to represent integer indexes if we can. The option of using strings does not prevent anyone from using the integer indexes instead for faster processing.

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

Re: Referencing Named Groups in RegEX

Post by Vadi »

To be honest if a pattern is really that complicated, there's something wrong in the design. Mudlet also has a very powerful trigger engine that you can utilize and break down patterns instead of making very complicated regexes. I've built several systems in Mudlet now and complicated regexes are very rare in them, haven't had a need for it myself.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Referencing Named Groups in RegEX

Post by tsuujin »

Vadi wrote:To be honest if a pattern is really that complicated, there's something wrong in the design. Mudlet also has a very powerful trigger engine that you can utilize and break down patterns instead of making very complicated regexes. I've built several systems in Mudlet now and complicated regexes are very rare in them, haven't had a need for it myself.
It really depends on the game's output and your need. Sometimes a big regex is still the easiest solution to a particular problem. I still wish we had named backreferences in all honesty; I've just accepted that it won't happen and found other ways around it.

Post Reply