regexpowerappsutmpowerapps-canvas

Query string in URL in Power Apps


I'm creating a UTM generator in Power apps. I have to remove the query string (utm_source, utm_medium and utm_campaign) from the URL that user can paste to the URL input. Also, I have to keep the rest on the valuse like utm_test

For example - from URL: www.testpage.html?utm_source=empsig_12&utm_medium=email&utm_campaign=aw_e_be+dk_agc_test&utm_test=test

I want to get URL like this:

www.testpage.html?utm_test=test

For now I have something like this:

Match(txt_URL.Text, "(utm_source)=([^&#]*&?)|(utm_medium)=([^&#]*&?)|(utm_campaign)=([^&#]*&?)").FullMatch

but it returns only the first match - utm_source=empsig_12&

thanks in advance


Solution

  • You can use MatchAll and then Concat the matches:

    Concat(
      MatchAll(txt_URL.Text, "(utm_(?:campaign|source|medium))=([^&#]*&?)"), 
      FullMatch, 
      ""
    )
    

    The regex matches