Allow a new line anywhere in the regex?
- by Scott Chamberlain
I am having a find a replace in a bunch of RTF documents, The basic pattern I need is
\{(?:\\\*)?\\field\\fldlock\{\\\*\\fldinst ?MERGEFIELD ?((?:\\.*?)?[\w\[\]]+?)(?:\\.*?)?\}(?:\{\\fldrslt\})?\}
However I then found out there could potentialy be a newline before each slash, so it turned in to this.
\{(?:\s*\\\*)?\s*\\field\s*\\fldlock\s*\{\s*\\\*\s*\\fldinst\s*MERGEFIELD\s*((?:\\.*?)?[\w\[\]]+?(?:\s*\\.*?)?)?\s*\}(?:\s*\{\s*\\fldrslt\s*\})?\s*\}
But then I hit this it fails
fees totaling $\protect {\field\fldlock{\*\fldinst MERGEFIELD ENTEROUTSTANDINGVETERINARYF
EES}}\plain\f0\fs24\prot
Is there way have to have it match a new line anywhere in the search too without adding (?:\r?\n)? everywhere?
EDIT
To clear up confusion on the new lines. I need to keep the newlines in the document, I only want to remove the newlines if they are inside my match, so in the final example I posted it should replace
fees totaling $\protect {\field\fldlock{\*\fldinst MERGEFIELD ENTEROUTSTANDINGVETERINARYF
EES}}\plain\f0\fs24\prot
with
fees totaling $\protect ENTEROUTSTANDINGVETERINARYFEES\plain\f0\fs24\prot