| Regular Expressions, or Regex
for short, are an essential tool for developers that must process
text, search for character strings within text and validate data
input by matching entered data with a pre defined pattern.
Many are often put off by the awkward syntax that regular expressions
use, understandably so, things can get quite ugly with a complex
regex. However, this rather cryptic syntax does make for extremely
powerful pattern matching. Lets take a simple example, imagine your
website asks users to enter some information, perhaps you would
like them enter their name, but you will only accept names that
5 characters long and begin with a capital letter. You could validate
this data with a simple regular expression:
As you can see, not many lines of code. We should point out that
the example above is just one way to achieve this result and is
a very simple example.
Regular expressions were until recently the reserve of developers
from a Unix background, people familiar with command line operations
and scripting languages such as Perl. However, today you will often
find regular expression support built into many Windows applications,
in particular search and replace tools. In fact, you can now use
the very Unix like syntax of regular expressions in your Microsoft
.NET applications.
|