Chapter 11: Regular Expressions

Download CD Content

The goal of this chapter is to introduce regular expressions and demonstrate their use in middleware programming. This will include comparing regular expression processing and the LIKE operator in SQL.


The origin of regular expressions, a system for defining patterns of character strings, lies in theoretical computer science; namely, the theory of formal languages. Regular expressions also served a practical function by being incorporated in the earliest UNIX editors.

Regular expressions can serve two overlapping roles in middleware projects. A common function of a PHP or ASP script is to validate text data submitted by the person at the client computer. Regular expressions are an exact match for this role. Regular expressions also can be used to manipulate character strings, extract parts, and/or replace parts. An example of this will be shown in the next chapter in which the address for a file is calculated using the address for the script itself.

After learning about regular expressions, you might want to use them for doing searches in the database. Standard SQL supports a facility for what can be called inexact or incomplete matches: the LIKE operator. For example, you can check if a field contains a string by combining the given string with wildcard characters. The LIKE operator does not accept regular expressions. In addition, MySQL has an operator called REGEXP that checks a field of a table against a regular expression pattern.

Creating Database Web Applications with PHP and ASP
Creating Database Web Applications with PHP and ASP (Charles River Media Internet & Web Design)
ISBN: 1584502649
EAN: 2147483647
Year: 2005
Pages: 125
Authors: Jeanine Meyer

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: