TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

[regex master requested!] regexp with several optional parts

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
dolphy



Joined: 09 Apr 2014
Posts: 9

PostPosted: Fri Apr 25, 2014 12:54 pm    Post subject: [regex master requested!] regexp with several optional parts Reply with quote

I'd like to parse skills output to store statistics for each skill. I'm having trouble coming up with a regular expression to capture all the possibilities. Any regex masters out there?:

Code:

Level   Skill                Pct   Cost     Skill                Pct   Cost
===============================================================================
Lvl  1: dagger               100%           spear                 85%         
        sword                 96%           enhanced damage      100%         
        mounted travel       100%           parry                 91%         
        rescue                79%           shield block          87%         
        recall                50%           scrolls                1%   x mana
        staves                 1%           wands                  1%         
Lvl  3: second attack         89%           
Lvl  5: kick                  92%  15 move 
Lvl  6: fast healing          84%           
Lvl 10: dodge                 86%           
Lvl 12: third attack          88%           
Lvl 16: pet                  100%  50 move 
Lvl 20: lore                 100%           
Lvl 28: lunge                 93%  20 move 
Lvl 30: berserk               85%  50 mana 
Lvl 35: dual wield            90%           


Code:

Level   Spell                Pct   Cost     Spell                Pct   Cost
===============================================================================
Lvl  5: armor                100%   5 mana 
Lvl 15: fortitude             95%  50 mana 
Lvl 18: refresh              100%  12 mana 
Lvl 20: protection evil      100%   5 mana  protection good       99%   5 mana
Lvl 28: infravision            1%   5 mana 
Lvl 32: giant strength         1%  20 mana  sanctuary             71%  75 mana
Lvl 34: rejuvenation          93%  12 mana 
Lvl 35: cancellation           1%  20 mana 
Lvl 39: haste                 71%  30 mana 
Lvl 40: grow                   1%  25 mana  shield                 1%  14 mana
        shrink                 1%  25 mana 
Lvl 45: stone skin             1%  50 mana 
Lvl 46: dispel magic           n/a          mass sanctuary         n/a         
Lvl 50: visegrip               n/a         
Lvl 60: nullify                n/a         


Some of the problems I'm having trouble handling together:

    - Not every line has a "Lvl" indicator"
    - Each line may have one or two skills/spells listed
    - Any skill/spell name might be comprised of multiple words (i.e. spaces may be part of the name)
    - Any skill spell may have a "cost" field
    - The "cost" field may be numeric, or "x", followed by "mana" or "moves"
    - The current percentage may be "n/a"
Back to top
View user's profile Send private message
Dorack024



Joined: 08 Oct 2014
Posts: 1
Location: Chicago

PostPosted: Wed Oct 08, 2014 9:18 pm    Post subject: Reply with quote

I just joined the community, but I do fancy myself as a bit of a regex wizard. I just started using tintin a couple days ago so I'm not sure what the default regex engine is. However, I do have a regex that fits your needs but it is done using the ruby regex engine.

(Lvl\s+\d+:)?(?!Lvl\s+\d+:)(.*?)(?=\s{2,})\s+(\d{1,3}%|n\/a)\s+(\w* [aemnov]{4})?

It has four match groups and you can see what each one is matching at http://rubular.com/r/TCkWScw312

Again, I'm not too familiar with how scripting in tintin works, but if you could script that out to a ruby interpreter that regex will catch all the stuff you want

Edited to disable smilies... they were messing with the regex
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Thu Oct 09, 2014 1:45 pm    Post subject: Reply with quote

@Dorack024: to show code without interferences from emoticons you can use the tag
Code:
[code]insert strange code here :) :D [/code]
Smile

as far as I know with the #SCRIPT function you can run even RUBY code
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group