Mixpanel Community Icon

Correct Formatting for regex_extract to Get String After ?

·
·

What is the correct formatting for a regex_extract function that is looking for any string after a literal "?" in the field?

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    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

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    To answer your question about the correct formatting for a regex_extract function in Mixpanel, let's refer to the relevant information from the knowledge sources.According to the Mixpanel documentation on Custom Properties, the regex_extract function has the following syntax: LBKSregex_extract(haystack, pattern, <optional capture group#> )LBKSFor your specific case, where you want to extract any string after a literal "?" in the field, you can use the following format: LBKSregex_extract(field_name, "\\?(.**)$", 1)LBKSLet's break this down: - field_name is the name of the field you're searching in - "\\?(.**)$" is the regex pattern: - \\? matches a literal question mark (the backslashes are needed to escape the special meaning of "?" in regex) - (.*) captures any characters after the question mark - $ ensures we match to the end of the string - 1 specifies that we want to return the first (and only) capture groupThis function will extract everything after the first "?" in the given field. If there's no "?" in the field, it will return null.Remember that Mixpanel uses the PCRE2 regex engine, so the exact behavior might differ slightly from other regex implementations you may be familiar with.

    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.