02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

326<br />

CHAPTER 9 ■ PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS<br />

Putting It All Together<br />

Now that you’ve got a general underst<strong>and</strong>ing of regular expressions, it’s time to use your new knowledge<br />

to write a regex pattern that will match any occurrence of the phrases regular expression or regex,<br />

including the plural forms.<br />

To start, look for the phrase regex: /(regex)/i (see Figure 9-10).<br />

Figure 9-10. Matching the word regex<br />

Next, add the ability for the phrase to be plural <strong>by</strong> inserting an optional es at the end:<br />

/(regex(es)?)/i (see Figure 9-11).<br />

Figure 9-11. Adding the optional match for the plural form of regex<br />

Next, you will add to the pattern so that it also matches the word regular with a space after it; you<br />

will also make the match optional: /(reg(ular\s)?ex(es)?)/i (see Figure 9-12).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!