Quantifier

What is a quantifier?

A quantifier describes a mathematical operator that determines the validity of statements. Quantifiers, also called quantifiers, are assigned to the so-called predicate logic. Predicate logic is an extension of propositional logic. Informally, quantifiers are also called written abbreviations of spoken statements.

Types

The most common types of quantifiers are all-quantors and existential quantifiers. Other types of quantifiers, such as number quantifiers or unique existential quantifiers, can be traced back to all-quantifiers or existential quantifiers.

An all quantifier can be interpreted as a conjunction, i.e. as a concatenation of logical AND links. It determines the validity of a statement form, for example A(?). ? represents a variable. The notation ∀? says "for all/every ? is valid". The all quantifier can be seen as an upside-down letter "A". The expression ∀? : ?² ≤ 0 means, for example: "for all ? it is true that ?² ≤ 0", where "for all" represents the all-quantor, ? the variable and ?² ≤ 0 the propositional form.

In contrast to an all-quantifier, an existential quantifier can be regarded as a disjunction, i.e. as a concatenation of logical OR operations. The expression ∃? describes "there exists at least one ?", for which the postposed statement form applies. ∃? : ?² ≤ 0 means in comparison to before: "there is at least one number ? to which the propositional form ?² ≤ 0 applies", i.e. the propositional form is true. The symbol ∃ can be seen as a horizontally mirrored letter "E".

For both all-quantifiers and existential quantifiers, the reference quantity to which the respective quantifier refers must be unambiguously defined. If it is not clear from the context, the reference quantity for all-quantors must be specified by the expression ∀? ∊ M : A(?), for existential quantifiers the expression ∃? ∊ M : A(?) can be defined. The element sign ∊ indicates that the object ∀? or ∃? is an element of a set M.

What are quantifiers in regular expressions (regex)?

Regular expressions, or regex for short, describe character strings which are used in programming languages or in the search-and-replace function and which are assigned to the Description of these chains by certain syntactic rules serve. Regex can be interpreted as a general notation for describing textual patterns and are used in textual analysis, structural as well as Data analytics.

Quantifiers in regular expressions specify the truth condition for a match in the search. The Quantors are divided into a greedy version and a non-greedy or inert version.. While a greedy version tries to find an element as often as possible, a lazy version tries to find an element as rarely as possible. The following table shows the notation of the standard quantifiers in their greedy and lazy versions.

Greedy
Quantifier

Support
Quantifier

Description
**?with zero or more occurrences.
++?with one or more occurrences.
???with zero or one occurrence.
{n}{n}?Conformity with exactly n Occurrence.
{n,}{n,}?Compliance with at least n Occurrence.
{n,m}{n,m}?Consistency with n to m Occurrence.

In addition to the described standard expressions in Regex, there are other special forms such as lookahead and lookbehind. These are used to search for expressions that return only a (relevant) part of the searched expression and are intended for further processing.

  • LookaheadIf, for example, every "a" in a text is searched for which is followed by the letter "b" and only "a" is to be returned, this can be achieved by Lookahead.
    The syntax "a(?=b)" searches for the term "ab" always returns only "a" as a result.
  • LookbehindThe opposite is true for lookbehind. The name lookbehind is explained by the fact that preceding characters are also included in the search.
    The syntax for "(? <=a)b" also searches for the term "ab", but always returns only "b" as a result.

Data Navigator Newsletter