What Bertalan said, but I think you want needle:
And replacement: $2
That is, if you always have literal string --\n before the part you want and a parenthesis ( after, and not inside, it.
What the regex does, is match the complete input but break it up in three parts:
- take anything up to --\n as $1
- take anything as short as possible as $2
- take anything starting with ( as $3
Now if you use RegexReplaceAll it will replace the complete input with the part stored as $2.
With the input you provided it will return:
You Cannot Change the Status to Pending Cancellation as the Materials charges are associated to it
I think your best bet is to use RegexReplaceAll from Community Commons marketplace module.
The needle in the haystack is a regular expression like: .*message\":\"([^\"]+)+.*, and then the replacement is $1
Use some regular expression tester (like regex101.com) to make sure