Using regular expressions
Regular expressions are at the heart of pattern-based text-processing. To use regular expressions effectively, one needs to understand them.
Everyone who uses ls
is familiar with glob style patterns. Glob rules are useful in many situations, but are too limited for text processing. Regular expressions allow you to describe patterns in finer detail than glob rules.
A typical regular expression to match an e-mail address might look like this:
[a-z0-9_]+@[a-z0-9]+\.[a-z]+.
If this looks weird, don't worry; it is really simple once you understand the concepts through this recipe.
How to do it...
Regular expressions are composed of text fragments and symbols with special meanings. Using these, we can construct a regular expression to match any text. Regular expressions are the basis for many tools. This section describes regular expressions, but does not introduce the Linux/Unix tools that use them. Later recipes will describe the tools.
Regular expressions consist of one...