DRAFT help

Publication date: 12/16/2025

Regex Function

Regex() searches for a pattern in a source string, returning the matched string if the search was successful. It can also transform a string into another string using the replacementString.

Regex(source, pattern, <replacementString>, <IGNORECASE>, <GLOBALREPLACE>);

By default, Regex() returns the matched text or numeric missing if the match fails. Case-sensitive matching is the default, but IGNORECASE disregards case. GLOBALREPLACE repeats the match until the entire string is processed, and returns the entire string if there was a match.

Example of Matching a String

In the following code, bus|train|car is a regular expression, and because it’s a string, it must be in quotation marks. The expression means match “bus” or ”train” or “car”. The following Regex() returns the matched word "bus":

sentence = "I took the bus to work.";
Regex( sentence, "bus|train|car" );

"bus"

You can capture the output of Regex():

sentence = "I took the bus to work.";
vehicle = Regex( sentence, "bus|train|car" );
write ("My vehicle: " || vehicle);

My vehicle: bus

Example of Replacing a String using GLOBALREPLACE

The modifier GLOBALREPLACE changes the behavior of Regex(). If the match succeeds, the entire source string is returned, with substitutions made in each place where the pattern matched. If there are no matches, the unchanged source string is returned.

sentence = "I took a red bus and then a blue bus.";
Regex( sentence, "bus", "car", GLOBALREPLACE);

"I took a red car and then a blue car."

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).