What are regular expressions?
One of the most common situations that come up is having an HTML form for users to enter data. Normally, we might be interested in the visitorís name, phone number and email address, and so forth. However, even if we are very careful about putting some hints next to each required field, some visitors are going to get it wrong, either accidentally or for malicious purposes.
Coding a script to check sensitive user data is sometimes pretty straightforward. But most of the time this process is not so easy. With current websites, weíll need to check the proper standardized format of an email address or a URL. That would be a nightmare for programmers, not to mention a confusing and inefficient error-prone process for checking data validity.
Hereís where regular expressions come in handy. A regular expression is a way of describing a pattern in a piece of text. In fact, itís an easy way of matching a string to a pattern. We could write a simple regular expression and use it to check, quickly, whether or not any given string is a properly formatted user input. This saves us from difficulties and allows us to write clean and tight code. Letís see in detail how to work with regular expressions.