web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Replacing Special Char...
Power Automate
Answered

Replacing Special Characters in string running slow

(1) ShareShare
ReportReport
Posted on by 160
Hello,
 
I am using the process described at this website Replace Special Characters in a String using Power Automate where you put all the special characters in an array and loop through the array to replace each special character in a given string.
 
My overall workflow is one that runs from Power Apps and creates a document set in a particular library. The overall flow works as desired but it is very slow and disrupts the user interaction with the app. 
 
I am running the workflow from the app so that I can get the document set link passed back to the app to be used in the app.
 
I tried the Concurrency Control but with that on, some of the special characters in the array are missed.
 
For clarity, I am using SharePoint lists as the backend. The users are entering action items, and the document set is the list item "ID - the action item title". So, if the user puts a special character in the Action item title it needs to be scrubbed out in Power Automate so the document set can be created. 
 
Are there alternatives to cleaning special characters out of a string?
Categories:
I have the same question (0)
  • Verified answer
    Valantis Profile Picture
    6,735 on at
     
    The loop-through-array approach is slow because it runs a sequential replace action for each character, and if you have 10-20 special characters that's 10-20 iterations with overhead per step.

    Fastest alternative: replace the entire loop with a single chained replace() expression in a Compose action.

    replace(replace(replace(replace(replace(replace(triggerBody()?['title'],'#',''),'\'',''),'&',''),'%',''),'+',''),'"','')
    Add more replace() wrappers for each character you need to strip. It looks long but executes as a single expression evaluation with no loop overhead, so it's significantly faster.

    If you need to keep it maintainable, an alternative is to use a single regex-style approach with the workflow expression functions. Unfortunately Power Automate doesn't have a native regex replace, but you can use a custom connector or Encodian's Replace action which supports regex patterns like [^a-zA-Z0-9\s-] to strip all non-alphanumeric characters in one step.

    For your specific use case (document set name from ID + title), the characters you typically need to remove are: # % & { } \ / < > * ? $ ! ' " : @ + ` | =
    A chained replace() covering those specific characters will be much faster than the array loop and won't have the concurrency issue.
     

     

    Best regards,

    Valantis

     

    ✅ If this helped solve your issue, please Accept as Solution so others can find it quickly.

    ❤️ If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

    🏷️ For follow-ups  @Valantis.

    📝 https://valantisond365.com/

    💼 LinkedIn

    ▶️ YouTube

  • David_MA Profile Picture
    14,956 Super User 2026 Season 1 on at
    If you have a subscription to Encodian, they have a utility action where you can replace values using a RegEx expression. I would need to double-check this, but to replace everything but letters and numbers, this RegEx expression would work: [^A-Za-z0-9]+
     
  • FW-07051511-0 Profile Picture
    160 on at
     
    It took me a while to type out the replace function but it seems to work. It's still slow but not as slow as it was. 
  • Valantis Profile Picture
    6,735 on at
    @FW-07051511-0 i am happy that it worked out man, have a nice day

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard