- Introduction
- What Is a "Regular Expression"?
- String Pattern-Matching
- Searching Files
- Compiling Regular Expressions
- Dynamically Emitting Compiled Regular Expressions
- Summary
What Is a "Regular Expression"?
Historically, scripting languages and tools like grep, awk, ObjectRexx, and Perl have had excellent support for regular expressions. Microsoft's Visual Studio .NET offers superlative support for using regular expressions, as implemented in the System.Text.RegularExpressions namespace.
I could look up a definition for the term regular expression, but instead let me provide an adequate definition in my own words: Regular expressions are a concise language with its own grammar, useful for performing text pattern-matching and search-and-replace operations.
Strings are prevalent in computing. Very few applications exist without some manipulation of string data. Regular expressions allow you to manipulate string data without writing a lot of custom code to do so. Instead of writing a lot of C# or Visual Basic .NET code to validate, parse, search, or replace strings and substrings, you can write a concise (and terse) regular expression and let the regular expression engine perform the string operation for you.
Regular expression engines have become quite advanced over the years, and it's very likely that the regular expression engine can perform significantly more advanced string operations than a programmer is likely able to write, even over several days or weeks. The only drawback is that you have to learn a language that can be very tersebut is thankfully very brief. I'll provide more than enough information to get you started, if you read on.