Skip to main content

Pattern Matching and Regular Expressions

In ObjectScript, there are two ways to check if a string matches a pattern: pattern matching (using the ? operator) and regular expressions (using the $Match function). $Match uses standard regular expression syntax, documented both within InterSystems IRIS documentation using the link above, and in many other books and websites.

The next few pages cover the pattern match operator. A pattern specification is a series of one or more partial patterns using the following syntax without spaces:


Quantity_1CodeOrLiteral_1Quantity_2CodeOrLiteral_2...Quantity_NCodeOrLiteral_N

In addition, you can enclose several partial patterns within parentheses, separated using commas, creating a list of alternatives. You precede the parenthesized section with a quantity, to account for optional or recurring sub-patterns within the specification.

Quantity Meaning - Code Meaning Code Meaning
3 Exactly 3   A Alphabetic (upper or lower) C Control characters
1.3 1 to 3   U Uppercase E Any character
.3 Up to 3   L Lowercase ANP Combination of codes
3. At least 3   N Numeric “abcdef” Literal string
. Any number including 0   P Punctuation    

Note that the pattern match codes in the table are the English language defaults. InterSystems IRIS locales allow you to specify alternate codes for different languages. Locales are beyond the scope of this tutorial.

Feedback