All base patterns (e.g. WORD, GROUP, RANGE) in a GLASS data type must be connected to another component (or group of components).
Two or more components can be joined in:
Both THEN and OR operators can be used together in a GLASS expression.
The THEN connector lets you join two or more search patterns or expressions such that they must be matched consecutively.
A location will be returned as a match if the GLASS engine detects a data string that is a combination of the all the THEN operators.
The generic GLASS syntax for THEN is:
[(]<search pattern or expression> THEN <search pattern or expression>[)]
()
is optional for
GLASS expressions where the logic and operator
precedence is straightforward.
However, they are encouraged to improve readability and to reduce potentially
unexpected results.ACME Corporation's regional customer ID is a 12-digit string
that starts with
a supported 2-character ccTLD (<ccTLD>
), followed by
a 9-digit serial number (<9-digit serial number>
), and
a single check digit (<check digit>
).
One approach when building this GLASS data type would be to define separate base patterns to search for the ccTLD, serial number, and check digit, and combine the base patterns using the THEN connector.
GLASS expression to search for the accepted ccTLD values:
MAP NOCASE 'ACME_CUST_ID_CCTLD' 'AU', 'IE', 'KR', 'SG', 'UK', 'US'
GROUP 'ACME_CUST_ID_CCTLD'
GLASS expression to search for the 9-digit serial numbers:
MAP 'INVALID_SERIAL_NUM' 0
RANGE DIGIT TIMES 9 EXCLUDE 'INVALID_SERIAL_NUM'
GLASS expression to search for the check digit:
RANGE DIGIT
The three GLASS expressions can be joined using the THEN connector to search for the regional customer ID number as a whole.
The equivalent GLASS code for the combined GLASS expressions is:
MAP NOCASE 'ACME_CUST_ID_CCTLD' 'AU', 'IE', 'KR', 'SG', 'UK', 'US'
MAP 'INVALID_SERIAL_NUM' 0
GROUP 'ACME_CUST_ID_CCTLD' THEN \
RANGE DIGIT TIMES 9 EXCLUDE 'INVALID_SERIAL_NUM' THEN \
RANGE DIGIT
The OR connector lets you join two or more search patterns or expressions such that expressions on either side of the OR operator may be matched.
A location will result in a match if the GLASS engine detects a data string that is a result of the expression on either side of the OR operator.
The generic GLASS syntax for OR is:
(<search pattern or expression> OR <search pattern or expression>)
()
is required when using
OR operators in GLASS
expressions to ensure that expressions within the parentheses are evaluated
first.ACME Corporation has received a Request for Information (RFI) on the following members of the Skywalker family:
You task is to develop a custom GLASS data type to search through ACME Corporation's databases for references to the Skywalker family, with the following assumptions:
, pipe |
,
comma ,
).1 | Leia Skywalker |
2 | Skywalker,Luke |
3 | Anakin|Skywalker |
GLASS expression to search for first names followed by the last name:
MAP NOCASE 'FIRST_NAMES' 'Anakin', 'Leia', 'Luke'
GROUP 'FIRST_NAMES' THEN RANGE ' |,' THEN WORD NOCASE 'Skywalker'
GLASS expression to search for the last name followed by the first names:
MAP NOCASE 'FIRST_NAMES' 'Anakin', 'Leia', 'Luke'
WORD NOCASE 'Skywalker' THEN RANGE ' |,' THEN GROUP 'FIRST_NAMES'
The two GLASS expressions can be joined using the OR connector to search for the names of the Skywalker family members, either as first names followed by last names, or last names followed by first names.
The equivalent GLASS code for the combined expressions is:
MAP NOCASE 'FIRST_NAMES' 'Anakin', 'Leia', 'Luke'
( \
(GROUP 'FIRST_NAMES' THEN RANGE ' |,' THEN WORD NOCASE 'Skywalker') \
OR \
(WORD NOCASE 'Skywalker' THEN RANGE ' |,' THEN GROUP 'FIRST_NAMES') \
)
The example in Part 1 - First Name Followed By Last Name can be written using the WORD in instead of GROUP base pattern component by using both THEN and OR in a single expression.
(WORD NOCASE 'Luke' OR WORD NOCASE 'Leia' OR WORD NOCASE 'Anakin') THEN \
RANGE ' |,' THEN \
WORD NOCASE 'Skywalker'
1 | Leia Skywalker |
2 | Luke,Skywalker |
3 | Anakin|Skywalker |
()
in THEN and OR Example
1, 'Luke', 'Leia', 'Anakin Skywalker', 'Anakin|Skywalker', and
'Anakin,Skywalker' will be returned as matches by the
GLASS pattern matching engine.