Trimming text

Good Afternoon,   Someone kindly helped me yesterday trim text but still allow new lines, However it is still allowing a space at the beginning of the lines which ideally we do not want. You can see below the 2nd two lines have a space at the start. The formula used is below: Does anyone know if I can add anything to trim the lines completely?       Thanks in advance
4 answers

Hi, me again.

So try this:

trim(replaceAll($Notes/Notes, '[ \t]*\R[ \t]*', '

What it does:

look for spaces/tabs before and/or after a line break (\R) and replaces them with just a line break. Then trim the result to remove spaces from beginning or end.


Normally, your proposed solution should work. Are you expecting [\t]+  in the middle of your notes attribute as well, or only at the beginning? Otherwise you could simply replace your replaceall with quotes instead of a space.


When I try to reproduce your case, it works normally for me, all the spaces are removed at the start and the end of the string. Have you tried debugging to see what your string changes to after you do the replaceall? There might be a hint there.


And after a replaceall and trimming:



Hi Jessica,


So, if I understand you correctly, you have a text with multiple lines and each line could have leading and trailing spaces. I'm not sure if this is possible with the replaceAll() function, but this might be an alternative that could work.



  1. Make sure you have the Community Commons marketplace module installed
  2. Create a SUB microflow with the string as an input parameter;
  3. Create a new string variable with an empty value (i.e. '’)
  4. Use the “String split” function that is available in the Community Commons module
    1. The input string is the input parameter “String"
    2. The split parameter should be a linebreak, i.e. '\n'
    3. Now, each line is stored in a separate object in the SplitItem entity
  5. Loop over the List of SplitItem
  6. In the loop, place a Change Object activity in which you apply the formula you've mentioned, but over the IteratorSplitItem/Value variable
    1. trim(replaceAll($IteratorSplitItem/Value, '[ /t]+', ' '))
  7. Add a Change variable activity, in which you add the IteratorSplitItem/Value


If you have the following string:

Test 1
   Test 2   
 Test 3     


This would be the result:

Test 1
Test 2
Test 3


Please note, if it would be possible through the replaceAll() function, that would be better and less work :)


Hope this helps,


Regards, Jeroen


Hi Martin,


Thank you for helping again. I very much appreciate it! It fixes one issue but then there is now another one. Though I am confident now it must be able to be done this way!



Results in the below – It trims it to the edge but now no longer trims in between. 



Thank you to all the answers! I would be lost without this forum!