O'Reilly logo

PHP and MySQL by Example by Marko Gargenta, Ellie Quigley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12Regular Expressions and Pattern Matching

/^[a-zA-Z][\w \.\-]+[a-zA-Z0-9]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,4}$/huh?

12.1 What Is a Regular Expression?

/^[a-zA-Z][\w\.\-]+[a-zA-Z0-9]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,4}$/ is called a regular expression and might look like jibberish, but by the time you finish this chapter, you will understand what all these symbols mean and how to use them. We will break the expression into very small units, and when all of the pieces have been explained, we will use it to validate an HTML form. Let’s start by defining a regular expression and what it is used for.

When a user fills out a form, you might want to verify that the format was correct before sending the data to a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required