Regular Expressions

Magic “between” string – works as long as there’s not any < or > in the string:

([\s\S]*?)

Example 1: Replaces all <span xml…></span> with <em></em>

<span xml:lang="en-US">([\s\S]*?)</span>

<em>$1</em>

Example 2: Special Footnotes

<span class="Endnote-reference char-style-override">([\s\S]*?)</span>

<sup><a href="#_edn$1">$1</a></sup>

Example 3: <sup>1</sup> —> Footnote

<sup>([\d]*?)</sup>

<sup><a href="#_edn$1">$1</a></sup>

Example 4a: French Number Formatting (1,123,456 => 1&nbsp;123&nbsp;456)

(\d*),(\d{3})

$1&nbsp;$2

Example 4b: French Number Formatting #2 (1 123 => 1,123)

(\d),(\d)

$1&nbsp;$2

…or try:
(?<=\d)\s(?=\d)

Example 5: French Number Formatting #3 ($1,100,100 => 1 100 100 $)

\$(\d*),(\d{3}),(\d{3})

$1&nbsp;$2&nbsp;$3$

Example 6: Killing off double spaces in WordPress template code

\n\n

\n

CMJ – 2021 (Web Experience Toolkit) Footnotes

English:

1. Start it with this:
<dt>Footnote 1</dt><dd id="fnX"><p>

2. End it with this:
</p><p class="fn-rtn"><a href="#fnX-rf"><span class="wb-inv">Return to footnote </span>X<span class="wb-inv"> referrer</span></a></p></dd>

3. Rename all the <dt>Footnote… with 1, 2, 3, etc.

4. Regular Expression time! Replace this:
<dt>Footnote ([\s\S]*?)</dt><dd id="fnX"><p>([\s\S]*?)</p><p class="fn-rtn"><a href="#fnX-rf"><span class="wb-inv">Return to footnote </span>X<span class="wb-inv"> referrer</span></a></p></dd>

…with this:
<dt>Footnote $1</dt><dd id="fn$1"><p>$2</p><p class="fn-rtn"><a href="#fn$1-rf"><span class="wb-inv">Return to footnote </span>$1<span class="wb-inv"> referrer</span></a></p></dd>

French:

1. Start it with this:
<dt>Note de bas de page 1</dt><dd id="fnX"><p>

2. End it with this:
</p><p class="fn-rtn"><a href="#fnX-rf"><span class="wb-inv">Retour à la référence de la note de bas de page </span>X</a></p></dd>

3. Rename all the <dt>Note de bas de page… with 1, 2, 3, etc.

4. Regular Expression time! Replace this:
<dt>Note de bas de page ([\s\S]*?)</dt><dd id="fnX"><p>([\s\S]*?)</p><p class="fn-rtn"><a href="#fnX-rf"><span class="wb-inv">Retour à la référence de la note de bas de page </span>X</a></p></dd>

…with this:
<dt>Note de bas de page $1</dt><dd id="fn$1"><p>$2</p><p class="fn-rtn"><a href="#fn$1-rf"><span class="wb-inv">Retour à la référence de la note de bas de page </span>$1</a></p></dd>