October 2024
Intermediate to advanced
272 pages
6h 54m
English
A general SNOBOL pattern is more complex than a mere string of characters. It’s defined recursively: it can be a simple string, the joining (concatenation) of two patterns, or a choice (alternation) between them, with the alternation operation taking precedence over concatenation.
Similar to regular expressions, SNOBOL uses a vertical bar | to denote alternation between two options. A pattern like P1 | P2 is considered a match if the subject string matches P1 or P2. The following example demonstrates how to use alternation to detect either “Alice” or “Bob” within a line of text:
| | LOOP line = INPUT :F(END) |
| | line "Alice" | "Bob" :F(LOOP) |
| | OUTPUT = "Found a match!" :(LOOP) |
| | END |
Read now
Unlock full access