cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gottijay2000
Advocate II
Advocate II

Replacing a string with mutiple commas by a single comma using Regex

i have a large string that is a result of a http call. This string is '@' separated, but within each item in the string i have multiple occurrences of commas that i will like replaced by just a simple comma.
An example of the string is  "Flat 1, Society Court,,,Aberdeen,Scotland@Flat 2, Society Court,,,Aberdeen,Scotland"
Basically i want this String to be in this format "Flat 1, Society Court,Aberdeen,Scotland@Flat 2, Society Court,Aberdeen,Scotland"

After which i can then split the text and store the results in a collection. This is what i have so far
ClearCollect(col_addresses, Split(Substitute(var_text,Match(var_text,"[,]{2,}").FullMatch,","),"@") )

 

What i have tried to do is find any matches in the string where there are multiple commas, and then replace them with a single comma, i then split the result. When i check the collection i just get the split on the original string with the commas still as they were.

 

it seems the Match function may not do the job or am i doing something wrong. Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@Gottijay2000 

You can put this string in a Text Input called TextInput1

 

Flat 1, Society Court,,,Aberdeen,Scotland@Flat 2, Society Court,,,Aberdeen,Scotland

 

Then put this code in another text label

 

Left(
  Concat(Filter(Split(TextInput1.Text,","),!IsBlank(Result)),Result&","),
  Len(Concat(Filter(Split(TextInput1.Text,","),!IsBlank(Result)),Result&","))-1
)

 

Your result will look like this.

 

Flat 1,Society Court,Aberdeen,Scotland@Flat 2,Society Court,Aberdeen,Scotland

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

1 REPLY 1
mdevaney
Super User
Super User

@Gottijay2000 

You can put this string in a Text Input called TextInput1

 

Flat 1, Society Court,,,Aberdeen,Scotland@Flat 2, Society Court,,,Aberdeen,Scotland

 

Then put this code in another text label

 

Left(
  Concat(Filter(Split(TextInput1.Text,","),!IsBlank(Result)),Result&","),
  Len(Concat(Filter(Split(TextInput1.Text,","),!IsBlank(Result)),Result&","))-1
)

 

Your result will look like this.

 

Flat 1,Society Court,Aberdeen,Scotland@Flat 2,Society Court,Aberdeen,Scotland

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,392)