Modifier(methods)
MatchRequirement
MustBeFound
- which means we must necessarily get a match from this regular expressionMustNotBeFound
- which means, based on this regular expression, we must not get a match
MatchRequirement | Match found | does this rule have any subrules ? | Result |
---|---|---|---|
MustBeFound | Yes | Yes | Continue processing subrules |
MustBeFound | Yes | No | Finish processing |
MustBeFound | No | Yes | Error (match must have been found) |
MustBeFound | No | No | Error (match must have been found) |
MustNotBeFound | Yes | Yes | Continue processing subrules |
MustNotBeFound | Yes | No | Error (match should not have been found) |
MustNotBeFound | No | Yes | Finish processing |
MustNotBeFound | No | No | Finish processing |
For example, we have a regular expression r"\d+"
and we want to get a match from it. We create a rule with the modifier MustBeFound
. If we get a match, we continue to process the subrules. If we don't get a match, we get an error.
Different situations
As you may have noticed, there is a difference between these two options:
MatchRequirement | Match found | does this rule have any subrules ? | Result |
---|---|---|---|
MustNotBeFound | Yes | Yes | Continue processing subrules |
MustNotBeFound | Yes | No | Error (match should not have been found) |
This is done so that if you should not find this, but you do find it, you can create a subrules for additional checks with modifiers. If nothing is found, the subcorrections will simply be skipped.
Extend Rule
Modification to extend the rule with subrules. This is a very important modifier, because it allows you to create a tree of rules, and also allows you to create a tree of rules inside a tree of rules, etc.
Matching mode
Before we looked at modifiers that affect one Rule
, but now we will study modifiers that affect all subrules
within one root rule
all_rules_for_all_matches
(default mode)all_rules_for_at_least_one_match (all_r_for_any_m)
at_least_one_rule_for_all_matches (any_r_for_all_m)
at_least_one_rule_for_at_least_one_match (any_r_for_any_m)
all_rules_for_all_matches
In this mode, all rules must be tested for all matches
Operation scheme of the mode
all_rules_for_at_least_one_match (all_r_for_any_m)
In this mode, all rules must pass the test for at least one match
at_least_one_rule_for_all_matches (any_r_for_all_m)
In this mode, at least one rule must pass the test for all matches.
at_least_one_rule_for_at_least_one_match (any_r_for_any_m)
In this mode, at least one rule must pass at least one match check
Matching counter
Before we see the following modifiers, let's see how text match capture works when a rule is triggered, for example pattern \d+
, for text 123 123 123 54 6 7 8
. We only get 123
, 6
, 7
, 8
.
What happened now?
For matches in the library we use IndexSet, this is necessary so as not to check once again all the rules of three matches 123
, but we always keep the number of identical matches. This way, we only keep unique values and keep a count of them so we always know how many times they are repeated.
counter_is_equal X
Adding a match counter, where the condition is:
there must be exactly
x
matches
counter_more_than X
Adding a match counter, where the condition is:
there must be greater than or equal to
x
matches
counter_less_than X
Adding a match counter, where the condition is:
there must be less than or equal to
x
matches