First parse examples

Let's start with some simple examples, where we have a product code that starts with the letter combination XY, followed by a digit, which we defined as a bitset digit in the previous section, for example, "XY6". We can parse this input with the rule block ["XY" digit]:

;-- see Chapter08/how-parse-works.red:parse "XY6" ["XY" digit]      ;== true

This works as follows. Look inside "XY6" from left to right, find a "XY", if found, then find one digit. If this is found and we are at the end of the input, return true. But in the code "XY67" there are two digits. The end of the input was not reached, and parse returns false:

parse "XY67" ["XY" digit]    ;== false

We can make it match by specifying the number of digits, like this: ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.