Ran across the following question the other day:

How would you find text in a field and add in a value retaining the original text

...I am trying to create a Flow formula that inserts a break before a date in a text field. The field does not contain breaks and want to fix that before an email notification gets sent. An example would be as such:

Original Field Text:

8/29/2023 These are some notes 8/28/2023 This is some more notes 7/30/2023 And here are some more

Desired Formula Outcome:

8/29/2023 These are some notes

8/28/2023 This is some more notes

7/30/2023 And here are some more


I ended up solving this by looking for repeated character pairings that fit the poster's syntax. In this case, that would be a space character, followed by a month designation, and ending with a '/' character. This would effectively skip the first instance of a date, but would reliably add line breaks to every additional date that was located.

Here is the formula (where 'Notes__c' represents a text field containing dated notes):

SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Notes__c, ' 12/', BR()+' 12/'),' 11/', BR()+' 11/'),' 10/', BR()+' 10/'),' 9/', BR()+' 9/'),' 8/', BR()+' 8/'),' 7/', BR()+' 7/'),' 6/', BR()+' 6/'),' 5/', BR()+' 5/'),' 4/', BR()+' 4/'),' 3/', BR()+' 3/'),' 2/', BR()+' 2/'),' 1/', BR()+' 1/')

Here is an image of the output in Salesforce:

'Notes' represents the raw field, where' Notes Formula' is our edited field

While this won't work for Long Text fields (which are more likely to contain notes), consider using nested SUBSTITUTE statements to avoid having to rely on more technically expensive 'find and replace' functionality within Flow/Apex!

Using SUBSTITUTE to reformat notes in Salesforce