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/