Skip to content

Instantly share code, notes, and snippets.

@Bellfalasch
Last active February 13, 2018 14:40
Show Gist options
  • Save Bellfalasch/9b1a04722f91f59f0097371198b208b1 to your computer and use it in GitHub Desktop.
Save Bellfalasch/9b1a04722f91f59f0097371198b208b1 to your computer and use it in GitHub Desktop.

Handy sets of Regex to perform effective search-and-replace / reorganizations in big HTML files.

Find chunks of HTML and reorganize them:

		<content:encoded><!\[CDATA\[<div class="sidebar">
([\s\S]*?)
<h2>Taktik</h2>
<p>([\s\S]*?)</p>\]\]></content:encoded>
		<content:encoded><![CDATA[<p>$2</p>
<div class="sidebar">
$1
]]></content:encoded>

Restructure tables with old data

<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2">(.*)</td>
<td colspan="3"></td>
</tr>
<tr>
<td rowspan="4"><img src="http://guide\.ffuniverse\.nu/wp\-content/assets/ff8/card/(.*)\.jpg" alt="(.*)" /></td>
<td colspan="3">Modify</td>
<td>Level / number</td>
</tr>
<tr>
<td colspan="3">(.*)</td>
<td>[1-9]0? / (.*)</td>
</tr>
<tr>
<td colspan="2">Element</td>
<td colspan="2">Class</td>
</tr>
<tr>
<td colspan="2">(.*)</td>
<td colspan="2">(.*)</td>
</tr>
<tr>
<td colspan="5">Skaffa kortet</td>
</tr>
<tr>
<td colspan="5"><em>(.*)</em><br />
(.*)</td>
</tr>
</table>
<div class="card-box">
	<strong>#$5</strong><br />
	<img src="http://guide.ffuniverse.nu/wp-content/assets/ff8/card/$2.jpg" alt="$3" width="62" height="62">
</div>
<h2>$1</h2>
<p>
    <strong>Klass</strong>: $7<br>
    <strong>Element</strong>: $6<br>
    "<strong>Modify Card</strong>": $4<br>
</p>
<h3>Så hittar du $1</h3>
<p><em>$8</em> - $9</p>

Resturcture old tables with varied format

<table>
(?:<thead>)?<tr>
<t[hd]>(?:<strong>)?Elemental Junctions(?:</strong>)?</t[hd]>
<t[hd]>(?:<strong>)?Status Junctions(?:</strong>)?</t[hd]>
</tr>(?:</thead>)?
(?:<tbody>)?<tr>
<td>(?:Elemental )?Attack: (.*)<br />
(?:Elemental )?Defense: (.*)</td>
<td>(?:Status )?Attack: (.*)<br />
(?:Status )?(?:Skydd|Defense): (.*)</td>
</tr>(?:</tbody>)?
</table>
<table>
<thead>
<tr>
	<th>Junctions</th>
	<th colspan="4">Element</th>
	<th colspan="4">Status</th>
</tr>
</thead>
<tbody>
<tr>
	<th style="text-align:right;">Attack:</th>
	<td colspan="4">$1</td>
	<td colspan="4">$3</td>
</tr><tr>
	<th style="text-align:right;">Skydd:</th>
	<td colspan="4">$2</td>
	<td colspan="4">$4</td>
</tr>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment