Input string for regular expression replace:
Result of replace expected:
The main problem not with added spaces but with nil at the end.
I've tried with Xcode:
And online: https://regexr.com/58umv
The result is the same (without nil).
I didn’t take a look at the regex, but we’ve got a removeTrailingNilformat argument especially for this purpose: https://take.ms/HDZCf
If you need this fix for anything else, let me know.
Additionally, the C# code behind “replace/…/…” seems trivial and you can take a look at that yourself if needed.