Page 1 of 1

Referencing Named Groups in RegEX

Posted: Sun Aug 14, 2011 4:57 am
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.

Re: Referencing Named Groups in RegEX

Posted: Sun Aug 14, 2011 6:43 pm
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.

Re: Referencing Named Groups in RegEX

Posted: Sun Aug 14, 2011 7:57 pm
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.

Re: Referencing Named Groups in RegEX

Posted: Sun Aug 14, 2011 10:58 pm
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.

Re: Referencing Named Groups in RegEX

Posted: Mon Aug 15, 2011 1:33 am
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.

Re: Referencing Named Groups in RegEX

Posted: Mon Aug 15, 2011 1:42 am
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.

Re: Referencing Named Groups in RegEX

Posted: Mon Aug 15, 2011 8:09 am
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.