Overview of regular expressions
A regular expression (regex) is a tool used to match, find, or manage corresponding data set text from Destiny Resource Manager to your Mobile Device Management (MDM) platform.
Regex is a language to describe your data. It can be used to transform, match all, or match part of your data. More specifically, a regex can perform searches, replace substrings, and validate string data.
Here are some of the most important concepts.
Regex Concept | Example | Notes |
---|---|---|
Parentheses ( ) |
([a-z]+) A group that matches one or more lowercase characters |
Parentheses are used to define capture groups. |
Square brackets [ ] |
[a-z] Any lowercase characters |
Square brackets are used to define character groups. |
Braces { } |
[a-z]{3} Any 3 lowercase characters |
Braces are used to limit numerically the number of matches. |
Shorthand \d \w \s |
d = [0-9] w = [a-zA-Z0-9_] s = [ \t] Shorthand for character groups |
These symbols are used to compress your regex. |
Caret '^' |
[^d] Not a number, ^chuck - lines starts with 'chuck' |
Two functions: 1) indicate beginning of line and 2) negation in character groups. |
Dollar '$' |
.*chuck$ Zero or more of any character, but must end in 'chuck' |
Signifies the end of input. |
Special Characters '.', '?','+', '*' |
. - any character
.? - 0 or one of any character
.+ - one or more of any character
.* - 0 or more or any character
[ab]* zero or more of any character |
. The dot matches any character.
? The question mark is the match-zero-or-one quantifier.
|
Escaping \. \ \[ |
\. - Matches a period \\ - Matches a backslash \[ - Matches an opening square bracket |
The '\' character is used to convert a regex special character to its literal value by 'escaping' it. |
Substitution
Substitution patterns let you modify the input (as represented by the sample data) using any data you can pull from the input (via capture groups) and/or any hard-coded text you want to add.
Legal Substitution Patterns
- Blank or no substitution pattern.
- Any number of text characters, mixed or unmixed with capture groups.
Capture Groups
A capture group is any closed parenthetical regular expression; the exception is that the entire regex (in parentheses or not) is also considered a capture group. Multiple capture groups can be in a regular expression, and a capture group can have any number of capture groups within it.
So the regex: ([0-9]+)([A-Z]{3})-([0-9]+) has 4 capture groups, 3 closed parenthetical expressions, and the entire match. You can access what is matched in the sample data for each capture group by specifying a $, followed by the numerical order of the capture group in the regex. For the example above, the entire match is referenced by $0, ([0-9]+) by $1, ([A-Z]3) by $2, and so on.
Sample Data
Enter text that you expect to receive from Google Workspace or Jamf Pro for this item.
Here are examples where the sample data is sampleData123:
Substitution Pattern | Regex Pattern | Output/Transformation |
---|---|---|
blank |
.* |
sampleData123 |
blank | ([0-9]) |
1 |
test | ([0-9]) |
test |
test:$1 |
([0-9]) |
test:1 |
$0:test:$1 | ([0-9]) |
1:test:1 |
$2:test:$1->$0 |
([a-zA-Z]+)([0-9]+) |
123:test:sampleData->sampleData123 |
Output
The result of applying your regex against your sample data is displayed in the output. The result is affected by the substitution pattern. If the substitution pattern is blank, then the output shows that which matches the entire regex. If the substitution pattern is not blank, then the output is the result of capture groups being applied to the substitution pattern.
It is not necessary to use capture groups; for instance, a regex of .* (match 0 or more of any character) and a substitution pattern of cheese is equivalent to specifying an Other text value of cheese.