Replace text RegEx question

I have the following text being passed by a Shortcut action to the Replace Text action

0|11-10 19:48:40|32.0
5|11-13 08:32:51|76.64
50|11-13 08:33:02|55.04
211|11-13 08:33:03|37.4

I want to replace the 5| at the start of the 2nd line with XXX

The match text \n5| finds the string to be replaced but \nXXX does not add back the newline. It just results in nXXX. How to add the newline so that 5| becomes XXX?

\n is only a newline in the regular expression. You either need to drop in a Shortcuts variable that is a newline into the substitution parameter, or you could use a reg ex placeholder like this.

A better way might be to forego the new lines and use a start of line instead (in case the first line has a match).

Hope that helps.

1 Like