LYCOS RETRIEVER
Regular Expression: Regular Expression Matching
built 634 days ago
Regular Expression is what Perl is famous for. What is a regular expression? A regular expression is simply a string that describes a pattern. Patterns are in common use these days; examples are the patterns typed into a search engine to find web pages and the patterns used to list files in a directory, e.g., ls *.txt or dir *.*. In Perl, the patterns described by regular expressions are used to search strings, extract desired parts of strings, and to do search and replace operations.
Source:
Regular Expression objects store patterns used when searching strings for character combinations. After the Regular Expression object is created, it is either passed to a string method, or a string is passed to one of the regular expression methods. Information about the most recent search performed is stored in the RegExp object.
Source:
If you've seen a regular expression before and thought it looked like alien space-algebra, it does, but have no fear - you'll be fluent in alien space-algebra in no time! To make the most of the power of regex, you need to be familiar with a few classifications of characters. Literals are normal text characters and can include whitespace (tabs, spaces, newlines, etc.). Unless modified by a metacharacter, a literal will match itself on a one-for-one basis. Metacharacters' power lies in how they are arranged and interpreted as wildcards. Metacharacters can be escaped with a backslash (\) to find instances of themselves, for instance, if you need to find a caret (^) or a backslash, as well as used in nested groups or other combinations.
Source:
There are three important parts to a regular expression. Anchors are used to specify the position of the pattern in relation to a line of text. Character Sets match one or more characters in a single position. Modifiers specify how many times the previous character set is repeated. A simple example that demonstrates all three parts is the regular expression "^#*." The up arrow is an anchor that indicates the beginning of the line.
Source:
Regular expressions figure into all kinds of text-manipulation tasks. Searching and search-and-replace are among the more common uses, but regular expressions can ... be used to test for certain conditions in a text file or data stream. You might use regular expressions, for example, as the basis for a short program that separates incoming mail from incoming spam. In this case, the program might use a regular expression to determine whether the name of a known spammer appeared in the "From:" line of the email. Email filtering programs, in fact, very often use regular expressions for exactly this type of operation.
Source:
A backslash (\) is a modifier that informs the regular expression engine to handle the character immediately following the backslash in a manner other than it's normal context. For example, a dollar sign ($) is a special character that normally represents "match the start of a string" in a regular expression pattern. But it's certainly possible that you may want to match an actual $ character. To do so, you escape the $ by placing a backslash in front it: \$. Similarly, the characters w, s, and d are normally interpreted as the actual characters w, s, and d. If you modify them using a backslash (\w, \s, and \d), then they represent "any word character", "any whitespace character", and "any numeric character," respectively.
Source: