self-hosted regex101
Running Regex101 Offline #
This is taken from the Intrepid individual’s github blog1
3 am on May 30, 2015 #
I was working on something when I suddenly needed some regex-fu. I opened a new browser tab, typed regex101 and pressed enter, and then I realized, I am at a place where sites usually take five fucking minutes to load up. I thought:
We need to improvise
I needed something that could work offline. I googled around (which took ages) to find an offline tool, but none of the results impressed me, and then I found this - a way of getting regex101 itself working offline. Turns out, some wget magic is all that we needed.
Cloning the site locally took around 10 minutes:
mkdir ~/regex101
cd ~/regex101
wget -r --no-host-directories --no-parent http://regex101.com
wget --output-document ./js/javascript.regex101.js http://regex101.com/js/javascript.regex101.js;
wget --output-document ./js/pcre.regex101.js http://regex101.com/js/pcre.regex101.js;
wget --output-document ./js/pcrelib16.js http://regex101.com/js/pcrelib16.js;
I used python’s http.server module to host the site:
The site loaded, but a few things were still out of place, like it still tried fetching jquery, font awesome, a font from google fonts etc. python, serve me a regex python3 -m http.server 8090
I then manually fetched each and every dependency, and edited the index.html to use the local ones.
Thirty minutes later I had a fully offline version up and running.
But we’re not done yet. I am not gonna
cd
into some directory and runpython3 -m http.server 8090
everytime I need regexes.We need to improvise.
Thanks to Linux Utility Lab, I learnt how to host sites using Apache this semester. I already had
apache2
installed. The rest was easy:
Create a directory that will host all the files:
vhostification > sudo mkdir -p /var/www/101regex.com
Put all the site required files there:
make a deposit sudo cp -r ~/regex101 /var/www/101regex.com
Create a site configuration:
Copy default:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/101regex.com.conf
Vim-it:
sudo vim /etc/apache2/sites-available/101regex.com.conf
Here’s how my config looked:
Now edit the hosts file to have a working url: vhostification <VirtualHost *:80> ServerName 101regex.com ServerAlias www.101regex.com ServerAdmin admin@101regex.com DocumentRoot /var/www/101regex.com </VirtualHost>
Open:
sudo vim /etc/hosts
Add line: 127.0.0.1 101regex.com
Enable the site
sudo a2ensite 101regex.com.conf
restart the server.
sudo service apache2 restart
I now have a fully functional Regex101 running locally at: 101regex.comI don’t even remeber what I wanted to do with regexes in the first place. So, I decided to write down a blog post.
By the way, It’s Four In The Morning.