c# - How do I parse a log from a game with regex and/or linq? -


i'm looking elegant way parse this. i'm hitting wall when comes regex knowledge , maybe regex not best answer?

i have 3 example sentences give example of want do. want to parse these 4 parts. attacker, attack-type, damage , target.

gandalfs's heavenly wrath dismembers you!

the holy prelate's slash wounds frodo.

your divine power decimates evil warlock!

attacker: 1 or several words first , words can identified either being "your" or end in 's.

attack-type: 1 or several words can identified between "attacker" , "damage".

damage: 1 or more (rare exists) words unique , limited. have list possible words. {"wounds", "decimates" etc}. not exists anywhere else no risk attacker named "wounds" or that.

target: 1 or several words can identified words after damage.

the following regex return match 4 captures each line:

^((?<attacker>your)|(?<attacker>.*?)'s)\s+(?<type>.*\s?)\s+(?<damage>wounds|decimates|dismembers)\s+(?<target>.*)\p{p}\s*?$ 

note need use following regex options work:

  • ignorecase
  • multiline
  • explicitcapture

you can query value of groups (attacker, type, damage, target) each match.

note need complete list of damages.

my regex test application set process matches returns following test data , regex:

attacker: gandalfs type: heavenly wrath damage: dismembers target:  attacker: holy prelate type: slash damage: wounds target: frodo  attacker: type: divine power damage: decimates target: evil warlock 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -