Nick Carr Profile picture
Tech Director / Threat Intelligence at Microsoft. Previously, Director of Incident Response & Intel Research at Mandiant. Former Chief Technical Analyst at CISA

Sep 10, 2020, 7 tweets

Pokéregex Challenge:
How many of the 719 Pokémon can you capture in a single regular expression that fits in a tweet?

Here's what to match: gist.githubusercontent.com/itsreallynick/…

Here are awesome regex resources: raw.githubusercontent.com/aloisdg/awesom… [this same text blob will also be used to measure FPs😊]

If you haven't done something like this before, here's a [crappy] bash one-liner to start:

sh -c 'pattern="your|regex"; echo 🎯 Pokémon:; curl -s gist.githubusercontent.com/itsreallynick/… | grep -ioE $pattern | wc -l; echo 🚯 Noise:; curl -s github.com/aloisdg/awesom… | grep -ioE $pattern | wc -l'

Oh, if it wasn't clear ... you put your regular expression in where it says "your|regex"

Because, as written, the results are pretty terrible 😄 [pictured]

This is similar to an interview question @TekDefense & I would ask @ Mandiant.
It's also an #APT32 hunting tweet. 😉🌶️

I loved to see interviewees think through or explain the longest common substring problem in CompSci.

For this particular question, I often think of regex performance and how helpful it is to anchor a match at the start or the end.

PICTURED: frequency analysis of (^start|end$)

If you want to sprinkle some data science on your regex, my favorite project in this space is:

Regex Generator++
regex.inginf.units.it
by Machine Learning Labs (@MaleLabTs)

If you want to play with this Pokémon dataset + fascinating regex ML, you can:
Import > Import raw data

If you're new and have questions, feel free to reach out.

If you want to play around with regex:
debuggex.com (@debuggex) is my favorite service with excellent visualizations

If you want to play a round with regex:
alf.nu/RegexGolf is for you. 😐🏌️ #RegexGolf

I liked this one from @KorbenD_Intel

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling