Allow a new line anywhere in the regex?
Posted
by
Scott Chamberlain
on Stack Overflow
See other posts from Stack Overflow
or by Scott Chamberlain
Published on 2011-06-26T01:14:38Z
Indexed on
2011/06/26
8:22 UTC
Read the original article
Hit count: 177
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
© Stack Overflow or respective owner