Regular Expressions in AMPScript

Did you know you can use regular expressions in AMPScript?

You can.

Here are some RegExMatch() snippets that I’ve used:


@s = input string
@p = pattern
@m = match
@o = output

Sample Code


Strip leading zeroes from a string

input: 0000012345
pattern: “^0*(\d+)$”
output: 12345

Check for all digits, no match

input: 12345x
pattern: “^\d*$”

Check for all digits, match

input: 12345
pattern: “^\d*$”
output: 12345

Replace parenthetical text with space

input: whee (whatever it is) whoop
match: (whatever it is)
pattern: “\s(.+)\s”
output: whee whoop

For further reading

RegExMatch() function
Concat() function
OutputLine() function
RegEx pattern reference
RegEx options reference

Leave a Reply

Be the First to Comment!

Notify of