Did you know you can use regular expressions in AMPscript?
You can.
Here are some RegExMatch() snippets that I’ve used:
Variables
@s = input string
@p = pattern
@m = match
@o = output
Sample Code
Output
Strip leading zeroes from a string
input: 0000012345
pattern: “^0*(\d+)$”
output: 12345
Check for all digits, no match
input: 12345x
pattern: “^\d*$”
output:
Check for all digits, match
input: 12345
pattern: “^\d*$”
output: 12345
Replace parenthetical text with space
input: whee (whatever it is) whoop
pattern: “\s(.+)\s”
match: (whatever it is)
replaced: whee whoop
For further reading
RegExMatch() function
Concat() function
OutputLine() function
RegEx pattern reference
RegEx options reference
(Visited 1,537 times, 1 visits today)