Whole-Input and Substring Matching

A whole-input match asks whether a complete string belongs to a language. A substring search asks whether some contiguous portion belongs.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a small input
  2. Check input with extra content
  3. Identify which span the pattern consumes
  4. Choose the API according to its validation contract

Trace a small input

If a pattern recognizes the single word ab, xabx has a matching substring and is not itself a member. See substring rules.

Check input with extra content

A validation example should include valid-looking text surrounded by unexpected characters. A search may intentionally report an occurrence's position instead. Language membership gives the whole-input question.[1]

Identify which span the pattern consumes

For pattern ab+ and input xxabbbz, a substring search can return abbb starting at index two. A whole-input match rejects that input because the leading and trailing symbols remain outside the pattern. See substrings and subsequences.

Pattern consumes one a followed by at least one b
Whole input abbb → accept
Embedded in xxabbbz → substring found, whole-input check fails

Choose the API according to its validation contract

A data validator usually needs the complete field checked. A document search may ask for a span. Test a valid word preceded or followed by extra characters.

References

  1. Michael Sipser, Introduction to the Theory of Computation ↩