I am needing assistance with a custom property involving REGEX_EXTRACT. It's not working correctly.
IF(@"""{"label":"Referring Domain","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$referring_domain"}"""@==UNDEFINED,"Direct",if(REGEX_EXTRACT(@"""{"label":"Referring Domain","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$referring_domain"}"""@, "(?:https?:\/\/)?(?:www\\.)?([a-zA-Z0-9-]+)\\.", 1)==@"""{"customProperty":{"allow_staff_override":false,"canUpdateBasic":true,"can_share":true,"composedProperties":{"_A":{"label":"Current URL","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$current_url"}},"description":"","displayFormula":"REGEX_EXTRACT( _A , \"https?:\\/\\/([^\\/]+)\", 1)","is_superadmin":true,"joinPropertyType":"string","mappedDataGroupId":null,"name":"Implementation Domain","pre_populated_entity_id":null,"propertyType":"string","referencedBy":[],"referencedDirectlyBy":[],"referencedRawEventProperties":["$current_url"],"referencesBorrowedProperty":false,"resourceType":"events","userInfo":{"email":"andrew@preferabli.com","id":2019561,"name":"Andrew Sussman"}},"customPropertyId":"5729689","joinPropertyType":"string","label":"Implementation Domain","propertyDefaultType":"string","resourceType":"event","type":"string","value":"Implementation Domain"}"""@,"Direct",REGEX_EXTRACT(@"""{"label":"Referring Domain","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$referring_domain"}"""@, "(?:https?:\/\/)?(?:www\\.)?([a-zA-Z0-9-]+)\\.", 1)))are you able to troublshoot?
Hi Andrew S., 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
Certainly! Let’s break down your issue with the custom property using REGEX_EXTRACT in Mixpanel.
1. Formula Structure
Your formula is quite complex and seems to be referencing property objects directly, rather than just the property names. In Mixpanel’s custom property formula language, you should reference properties by their names (e.g., $referring_domain), not by their full JSON object representations.
2. REGEX_EXTRACT Usage
The correct syntax for REGEX_EXTRACT is: LBKSREGEX_EXTRACT(haystack, pattern, <optional capture group#> )LBKSFor example: LBKSREGEX_EXTRACT($current_url, "https?:\\/\\/([^\\/]+)", 1)LBKSThis extracts the domain from a URL property, as shown in the documentation Custom Properties: Functions.
3. Troubleshooting Your Formula
- Property Reference: You are referencing properties using a stringified JSON object, which is not supported. You should use the property name directly, e.g., $referring_domain.
- Pattern: Your regex pattern looks reasonable for extracting a domain, but ensure it matches the format of your data.
- Undefined Handling: To check if a property is undefined, use the defined() function.
4. Example Correction
Here’s how you might rewrite your formula: plaintext if( not(defined($referring_domain)), "Direct", REGEX_EXTRACT($referring_domain, "(?:https?:\\/\\/)?(?:www\\.)?([a-zA-Z0-9-]+)\\.", 1) )LBKS- This checks if $referring_domain is defined. If not, it returns "Direct".
- Otherwise, it applies the regex to extract the domain.
5. Reference
You can find more about the REGEX_EXTRACT function and property referencing in the official documentation here.---Summary:
- Reference properties by name, not by JSON object.
- Use defined() to check for undefined properties.
- Use the correct REGEX_EXTRACT syntax.If you still have issues, please provide the exact error message or describe what’s not working as expected, and I can help further!
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.
Thank you. the complex JSON representation of the property object is a function of copy/paste from the Mixpanel modal. But you did correct the Regex issue which was the requirement for multiple \\'s. I had (?:https?:\/\/)?(?:www\\.)?([a-zA-Z0-9-]+)\\. you had (?:https?:\\/\\/)?(?:www\\.)?([a-zA-Z0-9-]+)\\.
Let me check the knowledge base for you again. One moment! 📚
Based on the Mixpanel documentation, the REGEX_EXTRACT function uses the PCRE2 regex engine and expects the pattern to be a valid regular expression string. Your regex pattern: LBKS([a-zA-Z0-9-]+\\.(?:com(?:\\.[a-z]{2})?|net|org|co\\.[a-z]{2}|[a-z]{2,}))LBKSis generally correct for matching domains like [example.com](http://example.com), [example.co.uk](http://example.co.uk), etc. However, in Mixpanel's formula editor, you need to double-escape backslashes, so each \ should be written as \\ in the formula string.Example usage in Mixpanel:Key points from the documentation:
- Use property names directly (e.g., $referring_domain).
- Patterns must be double-escaped in Mixpanel formulas.
- The REGEX_EXTRACT function returns the first capture group if you specify 1 as the third argument Custom Properties: Functions.If you are still experiencing issues, please ensure your property contains the expected string format and that you are using the correct number of backslashes in your pattern.
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.
kapa.ai why is the above not turning www.google.com into google.com
Let me check the knowledge base for you again. One moment! 📚
I'm sorry, but the knowledge sources do not contain explicit information about why your specific regex pattern does not transform [www.google.com](http://www.google.com) into [google.com](http://google.com) within Mixpanel's custom property formulas. The documentation provides examples of using REGEX_EXTRACT to extract domains from URLs, but it does not cover handling angle brackets (< > ) or pipe characters (|), nor does it describe transforming or replacing text—only extracting substrings using capture groups Custom Properties: Functions.If you need to extract just the domain (e.g., [google.com](http://google.com)) from a string like [www.google.com](http://www.google.com), ensure your regex is designed to ignore the www. prefix and does not include angle brackets or pipes in the match. However, the documentation does not provide a built-in way to perform replacements or to handle the full transformation you described.If you need more advanced string manipulation (such as removing www. or handling special characters), you may need to preprocess your data before sending it to Mixpanel, as the custom property functions are primarily for extraction and basic transformation, not full string replacement or formatting.If you have further details or a different example, please provide them, and I can help clarify based on the available documentation.
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.
