PHP Regex tutorial

Have you ever wondered how web applications do validation on forms? How does the app know when your input is really an email address? In most PHP applications, this is done using regular expressions (Regex).

I’ve previously posted about how to defend against XSS and SQL injection. Checking strings with a white list of allowed characters is one of the easiest changes a developer can make. Regex makes this easy in most programming languages.

In that post I linked to RegexOne. The site had a pretty good cheatsheet covering how regex is useful. This is only really helpful if you are familiar with how regex works.

If you’re looking for a more complete tutorial, try his. Guru99 has reached out to me to promote their new tutorial: PHP Regular Expressions Tutorial: Preg_match, Preg_split, Preg_replace. It looks like a pretty comprehensive tutorial. I suggest looking at that to learn some of the basics behind regex.

Leave a Reply