Mastering Regex

November 17, 2018

Using regex skillfully could be classified as wizardry magic. Lately I’ve been trying to improve this dark art because it has so many applications. I’ve found that tutorials or StackOverflow answers usually go from 0 to 100% mastery so quickly that it’s difficult to understand what exactly is going on. With that said I recently found the modules from https://regexone.com/ really helpful!

Below are just a few basic examples (I fully understand) that I’ve crafted to help me in the future (Note I’m in no way a wizard yet, so there is probably a better way to do some of these). I’ll probably add to this list as I continue to learn and find interesting things.

# Match the entire line that doesn't begin with 108.4.27.11, helpful for log files
/^[^108\.4\.27\.11].*$
# Match the entire line if "xmlrcp" or "wp-login" are included in the line
/^.*(xmlrpc|wp-login).*$