Last active
February 7, 2022 10:41
-
-
Save wvpv/a0f63889a291a27533dd to your computer and use it in GitHub Desktop.
SFMC AMPScript RegEx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%[ | |
var @s, @o, @p, @m | |
output(concat("<br>Strip leading zeroes from a string")) | |
set @s = "0000012345" | |
set @p = "^0*(\d+)$" | |
set @o = RegExMatch(@s, @p, 1) | |
output(concat("<br>input: ", @s)) | |
output(concat('<br>pattern: "', @p, '"')) | |
output(concat("<br>output: ", @o)) | |
output(concat("<br><br>Check for all digits, no match")) | |
set @s = "12345x" | |
set @p = "^\d*$" | |
set @o = RegExMatch(@s, @p, 0) | |
output(concat("<br>input: ", @s)) | |
output(concat('<br>pattern: "', @p, '"')) | |
output(concat("<br>output: ", @o)) | |
output(concat("<br><br>Check for all digits, match")) | |
set @s = "12345" | |
set @p = "^\d*$" | |
set @o = RegExMatch(@s, @p, 0) | |
output(concat("<br>input: ", @s)) | |
output(concat('<br>pattern: "', @p, '"')) | |
output(concat("<br>output: ", @o)) | |
output(concat("<br><br>Replace parenthetical text with space")) | |
set @s = "whee (whatever it is) whoop" | |
set @p = "\s\(.+\)\s" | |
set @m = RegExMatch(@s, @p, 0, "IgnoreCase") | |
set @o = replace(@s, @m, " ") | |
output(concat("<br>input: ", @s)) | |
output(concat('<br>pattern: "', @p, '"')) | |
output(concat("<br>match: ", @m)) | |
output(concat("<br>replaced: ", @o)) | |
]%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah looks great, Thanks Adam.