Applying a REQUIRE rule to a base pattern instructs the GLASS engine to report a match only if the base pattern is explicitly represented in the selected MAP namespace(s).
The generic GLASS syntax for REQUIRE is:
<search pattern> REQUIRE [STRIP|TRIM] <namespace>
ACME Corporation defines a general base pattern to
search for 2-digit strings that represent the month <MM>
component in the
worldwide customer ID.
RANGE DIGIT TIMES 2
Since DIGIT represents all integers
between 0
to 9
, the GLASS pattern above will
match any 2-digit string from 00
to 99
.
As there are only 12 valid months in a year, the
REQUIRE pattern rule is applied so that only
a specific range of 2-digit numbers (e.g. 01
to 12
) that are defined
in a given MAP namespace
(MONTH_OF_YEAR_LOOKUP) are returned as a
match.
MAP 'MONTH_OF_YEAR_LOOKUP' 1-12
RANGE DIGIT TIMES 2 REQUIRE 'MONTH_OF_YEAR_LOOKUP'
The equivalent configuration in GLASS Studio Visual Builder mode is:
An alternative way to define the expression without using the
REQUIRE keyword would be to define an explicit
range of valid months (e.g. 01
, 02
, …, 11
, 12
) in a
MAP namespace and reference it from the LIST
(GROUP) component.
MAP 'MONTH_OF_YEAR_LOOKUP' '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'
GROUP 'MONTH_OF_YEAR_LOOKUP'
If the TRIM modifier is defined, non-alphanumeric characters are removed from the leading and trailing ends of the matched pattern prior to looking up the matched pattern in the REQUIRE namespace.
If the STRIP modifier is defined, all occurrences of non-alphanumeric characters are removed from the matched pattern (not just leading or trailing characters) prior to looking up the matched pattern in the REQUIRE namespace.
Non-alphanumeric characters refer to any character outside of the ASCII range of
letters and digits (e.g. ^0-9a-zA-Z
); however this may also depend on the
locale in which the GLASS engine is running.
MAP 'NUMBER_RANGES' 000_000-499_999, 600_000-999_999
MAP 'BAD_NUMBERS' 111_111, 666_666, 888_888, 999_999
WORD '<' THEN \
( \
(RANGE DIGIT TIMES 1-6) OR \
(RANGE DIGIT TIMES 1-3 THEN WORD ',' THEN RANGE DIGIT TIMES 3) \
) REQUIRE STRIP 'NUMBER_RANGES' EXCLUDE 'BAD_NUMBERS' THEN \
WORD '>'
With the STRIP operator applied to the above GLASS expression, Line 1, Line 2 and Line 3 below will be returned as match locations by the GLASS engine:
1 | <0> |
2 | <0,123> |
3 | <444444> |
4 | <111,111> |
5 | <555,555> |
6 | <1000,000> |
Line 4 will not be matched as 111,111
is present in the
BAD_NUMBERS namespace referenced by the
EXCLUDE rule.
Line 5 and Line 6 will not match as both numbers are outside the range of valid numbers as defined in the NUMBER_RANGES namespace referenced by the REQUIRE rule.
See EXCLUDE rule and Syntax Overview - Integers for more information.
To add a REQUIRE rule for a base pattern in GLASS Studio Visual Builder Mode:
Selected namespaces will be added to the Map(s) Selected pane. See MAP Namespace for more information.
To edit a REQUIRE rule:
To remove a REQUIRE rule: