How to determine deviations in a sequence from a template?

I want to find passages where the sequence of actions deviates from the given pattern and cannot find a smart solution for this, although the problem sounds very simple.

The purpose of the template is to describe somehow the usual sequence. More specifically: "What actions should or should not be contained in the sequence of actions and in what order?" Then I want to combine the sequence of actions with the template and detect deviations and their locations.

My first approach was to do this with regular expressions. Here is an example:

Example 1:
Pattern: A.*BC
Sequence: AGDBC (matches)
Sequence: AGEDC (does not match)

Example 2:
Pattern: ABCD
Sequence: ABD (does not match)
Sequence: ABED (does not match)
Sequence: ABCED (does not match)

Example 3:
Pattern: ABCDEF
Sequence: ABXDXF (does not match)

, , . , , . , , . . .

, , ANTLR. , . . ?

+3
3

- , , , .

, , DFA, . , , , .

, , .

Java , CharSequence

   java.util.regex.Pattern.matches(String regex, CharSequence input) 

.

. .

0

Find an open source implementation of regular expressions and add a hook to return / set / print / save the index in which it fails if this comparison does not match. Alternatively, write your own RE engine (not for the faint of heart) so that it does exactly what you want!

0
source

All Articles