Forum


Replies: 5   Views: 1218
Placeholders are split across xml nodes
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 01-09-2021 - 15:35

Hello,

We think the problem is that you need to include all characters (<, >, :...), not only letters, numbers, _ ... as set in [A-Z0-9\s\-_]

If we try a more generic regex using your regex as base:

\{\{(?:#){0,1}(?:.)+\}\}

The placeholder in the XML is returned correctly.

Also note that this regular expression (and the new one you have posted) will match if you have {{ and }}, but MS Word may break them, for example:

<w:r>
   <w:rPr>
      <w:b w:val="false"/>
      <w:bCs w:val="false"/>
   </w:rPr>
   <w:t>{</w:t>
</w:r>
<w:r>
   <w:rPr>
      <w:b w:val="false"/>
      <w:bCs w:val="false"/>
   </w:rPr>
   <w:t>{USER</w:t>
</w:r>
<w:r>
   <w:rPr/>
   <w:t>_N</w:t>
</w:r>
<w:r>
   <w:rPr>
      <w:b w:val="false"/>
      <w:bCs w:val="false"/>
   </w:rPr>
   <w:t>A</w:t>
</w:r>
<w:r>
   <w:rPr/>
   <w:t>ME}</w:t>
</w:r>
<w:r>
   <w:rPr/>
   <w:t>}</w:t>
</w:r>

A more generic regex would be:

\{(?:.)*\{(?:#){0,1}(?:.)+\}(?:.)*\}

The easiest approach is using a single symbol ($, |, @...) or the default ${ } to wrap placeholders; in these cases you don't need to change the default regex. But if you want to customize it using {{ }} or others such as {[ ]}, $[ ]$ then a generic regex such as the previous one must be generated.

Regards.