Fontstats Plugin

Today I finished a little WordPress plugin I’ve been working on.

It’s a two part plugin, one php script collects data from any Norwegian designer on DaFont by visiting each site, and by the power of Regex-Grayskull it inserts it into a database on my website.

The WordPress plugin then selects the last sampled date and displays it in a HTML-table on any post or page where I insert the registered shortcode.

Here’s the result:

No.DownloadsDesignerDate Sampled
13180091Fontourist - Hans Gerhard Meier2018-01-11
22307029CheapProFonts - Roger S. Nelsson2018-01-11
31227379Flight of the Dragon - Hasan Guven2018-01-11
4407689Moonbase Press - Svein Kåre Gunnarson2018-01-11
5402166Espen Morten Kvalheim2018-01-11
6306375Martin Holm2018-01-11
7230160Norwegian Ink / Design for Dough - Frode Nordbø2018-01-11
8203762Thor Christopher Arisland2018-01-11
9168370211178 Creative Agency - Morten Talleivsen2018-01-11
1092931McKack2018-01-11
1175146Digital Flame Studios - sindre små2018-01-11
1271980Intense2018-01-11
1360710huskmelk - Rashid Akrim2018-01-11
1460042Kyrre Honohan2018-01-11
1539464Atle Mo2018-01-11
1635259Erik Jeddere-Fisher2018-01-11
1726578Mark Lund2018-01-11
1825639Lisa2018-01-11
1919580Kristian Dalen2018-01-11
2018765Erik Holm2018-01-11
2112433Alexander Rossebø2018-01-11
229182Boksen2018-01-11
236624Manuela Hardy2018-01-11
246149Mattis Folkestad2018-01-11

Regex 101

Today I received an email from the store I used to work at asking me to make a printer friendly version of an online table of information.

As I learned more about regular expressions from the “INF3331” course I took this fall, solving this problem proved to be way easier than any previous attempts at the likes of it.

At times I’ve thought that regexes are harder to read and debug than ordinary programming languages, but with a good editor like Atom or the regex101 page, it all became a lot less stressful.

As far as editors go, I have to admit that I still use emacs when I’m not using an IDE or GUI-editor.

Note to self about regular expressions.

(.*?) to capture zero or more characters in a non-greedy manner

(?:.*?) for the same grouping without backreferences.

$1 or $[group-number] for backreferences in JavaScript and Atom

\1 or \[group-number] for backreferences in Python, PHP.

Perl and PHP also uses \g1 or \g[group-number] for backreferences.

The following characters need to be escaped in regex:

.^$*+?()[{\|