How can I combine a REGEX_MATCH and REGEX_REPLACE statement in a custom property?
Hi Lois, Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> đź‘‹
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To combine REGEX_MATCH and REGEX_REPLACE statements in a custom property in Mixpanel, you can use the IF function along with these regex functions. Here's how you can structure it:LBKSIF(REGEX_MATCH(property, pattern), REGEX_REPLACE(property, pattern, replacement), original_property)LBKS
This structure allows you to first check if a pattern matches using REGEX_MATCH, and if it does, apply REGEX_REPLACE. If the pattern doesn't match, it will return the original property value.Here's an example of how you might use this in practice:LBKSIF(REGEX_MATCH(email, "^[^@​]+@​(.+)$"), REGEX_REPLACE(email, "^[^@​]+@​(.+)$", "$1"), email)LBKS
This example would extract the domain from an email address if it matches the email pattern, or return the original email if it doesn't match.Remember that REGEX_MATCH returns true if the pattern matches any part of the string, while REGEX_REPLACE replaces parts of a string that match a regular expression with a different string Custom Properties Functions.When creating custom properties, you can use the formula bar to define these complex transformations. You can also use Ctrl + Space to see a list of available functions and their descriptions while writing your formula Creating a Custom Property.
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.