How to parse a log from a regexp game and / or linq?

I am looking for the most elegant way to make it out. I just click on the wall when it comes to my meaning of regular expressions, and maybe regular expression is not even the best answer?

I have three example sentences to give an example of what I want to do. I want to make them into four parts. Attacker, type of attack, damage and target.

Gandalfs heavenly wrath KILLS you!

The Holy Prelate cuts through Frodo's wounds.

Your divine power destroys the evil Warlock!

Attacker: One or more words that are always first, and words can be identified by either "Your" or end in s.

Type of attack: one or more words that can only be identified by the fact that they are between โ€œattackerโ€ and โ€œdamageโ€.

Damage: one or more (rare, but existing) words that are unique and limited. I have a list of possible words. {"wounds", "destroyed", etc.}. They do not exist anywhere, so they do not risk that the attacker is called "wounds" or something like that.

Purpose: one or more words that can be identified that they are all words after damage.

+3
source share
2 answers

The following regex will return a match with four captures for each row:

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

, :

  • IgnoreCase
  • MultiLine
  • ExplicitCapture

(, , , ) .

, .

, , :

Attacker: Gandalfs
Type: heavenly wrath
Damage: DISMEMBERS
Target: you

Attacker: The Holy Prelate
Type: slash
Damage: wounds
Target: Frodo

Attacker: Your
Type: divine power
Damage: decimates
Target: the evil Warlock
+2

, /.

ANTLR:

http://www.antlr.org/

, , ANTLR #, .

LINQ.

0

Source: https://habr.com/ru/post/1777993/


All Articles