2

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

1 Answers1

0

You can use MatchAll and then Concat the matches:

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

The regex matches

  • (utm_(?:campaign|source|medium)) - Group 1: utm_ and then either campaign, source or medium
  • = - a = char
  • ([^&#]*&?) - Group 2: zero or more chars other than & and # and then an optional &.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563