Maptitude GISDK Help

Regular Expressions

You can match string expressions against full regular expressions. The syntax is based on the ECMAScript specification for regex patterns that is used in Javascript. A good description of the rules can be found at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

 

Regex patterns can be specified either as regular strings or with a literal syntax delimited by '/' characters. For example, the following expressions will all make a successful match:

 

"abcdef" matches /bcd/

"abcdef" matches "/bcd/"

"abcdef" matches "bcd"

 

The first way to match against regex patterns is to use the relational operator "matches" as in the above example. This returns a boolean value indicating whether the pattern is found in the string. This operator can also be used in SelectByQuery expressions and in formula field expressions. For example:

 

test_zip = "02461"

if test_zip matches /^[0-9]{5}$/ then

   is_valid = True

 

SelectByQuery("Valid", "several", "Select * where ZIP matches /^[0-9]{5}$/")

 

You can also use the following methods on string variables:

 

string.match(regex)

Returns an array containing the matched results, or null if there were no matches. The first element in the array is the full matched sequence and is followed by the captured sub-matches that are specified by parentheses in the regex pattern.

 

name = "John Doe"

results = name.match(/^(\S+)\s+(\S+)$/)

//results = {"John Doe", "John", "Doe"}

 

string.replace(regex, format)

Returns a string where the matched sequence is replaced by the format string. The format string can include the replacement patterns documented at

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

 

name = "John Doe"

result = name.replace(/^(\S+)\s+(\S+)$/, "$2, $1")

//result = "Doe, John"

Additional Flags

Using the literal syntax, you can optionally append one or more of the following flags to the regex pattern that change how the matching operation is applied:

 

Flag

Meaning

i

ignore case

g

global match

RegEx Class

See Address Standardization for a description of the RegEx class, which is a utility class in the standard interface intended to be used with address standardization.

 

 

©2025 Caliper Corporation www.caliper.com