Unfortunately you are fighting with special characters: ^
, ()
, |
.
You need to escape all of them. So you can use this regex (see it in action):
\^([^\^]+?)(\(S\))?(\(N\))?(\^.*)
and replace with this:
$2$3^$1$4
I assumed that you have (S)
and (N)
only after first tag. Output looks like this:
^901A-123^DESC,OF,PROD,AND,STUFF^$28.87^$23.10^--^--^--^--^^
(N)^123B-C45^DESC,OF,PROD,AND,STUFF^$1,224.87^$1,041.10^--^--^--^--^^
(S)(N)^333-11^DESC,OF,PROD,AND,STUFF^$510.67^$459.50^$382.90^2^$357.40^4^^
(S)^333-987M-88^DESC,OF,PROD,AND,STUFF^$608.77^$547.90^$456.50^2^$426.10^4^^
Explanation
Regex:
\^ # match '^' character
([^\^]+?) # group 1 : match any char other than '^' one or more times, non-greedy
(\(S\))?(\(N\))? # group 2-3: match "(S)" and/or "(N)" or none of them
(\^.*) # group 4 : match '^' and then everything
Replacement:
$2$3^$1$4 # concatenate group 2, then 3 and 1 and 4 after a '^' character