REQUIRE Rule

Overview of the REQUIRE Rule

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).

GLASS Studio REQUIRE Rule

The generic GLASS syntax for REQUIRE is:

<search pattern> REQUIRE [STRIP|TRIM] <namespace>

REQUIRE Example 1

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:

  • Data type component: RANGE
    • Data pattern to search for (Select a keyword): DIGIT
    • Repeat Character/Octet (TIMES) option: Checked, 2 times
    • Require (REQUIRE) rule:
      • MAP Label: MONTH_OF_YEAR_LOOKUP
      • MAP Entries: 1-12

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'
  • Data type component: LIST (GROUP)
    • Data pattern to search for (+ Create new map):
      • MAP Label: MONTH_OF_YEAR_LOOKUP
      • MAP Entries: 1-12

TRIM and STRIP Modifiers

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.

REQUIRE Example 2

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.

Adding REQUIRE Rules

To add a REQUIRE rule for a base pattern in GLASS Studio Visual Builder Mode:

  1. Add and define the data pattern for a RANGE component.
  2. In the Add Pattern Rules pane, click on Require.
    GLASS Studio Add REQUIRE RuleGLASS Studio Add REQUIRE Rule Pane
  3. Define the namespace(s) to be referenced by the REQUIRE operator by:
    • Clicking on Create Map and selecting the newly added MAP namespace, or
    • Selecting an existing MAP namespace from the Select Map(s) pane.

    Selected namespaces will be added to the Map(s) Selected pane. See MAP Namespace for more information.

  4. (Optional) Click to remove a selected MAP namespace from the REQUIRE rule.
  5. (Optional) Select the TRIM (TRIM) or STRIP (STRIP) option to remove non-alphanumeric characters from the matched pattern prior to looking it up in the selected namespace(s). See TRIM and STRIP Modifiers for more information.

Managing REQUIRE Rules

To edit a REQUIRE rule:

  1. Left click anywhere in the component to open the base pattern form.
  2. Click on the Down icon next to the REQUIRE panel.
  3. Add or remove namespaces, and click Close.

To remove a REQUIRE rule:

  1. Left click anywhere in the component to open the base pattern form.
  2. Click on the Trash icon next to the REQUIRE panel.
    GLASS Studio Delete REQUIRE Rule