at32 Reverse Proxy Online Documentation - Regular Expressions This is a trimmed version of Andrey V. Sorokin's explanation of RE. Also check out his program for learning RE. This also features numerous interactive examples and should allow you to create the regular expression that you need in a short space of time.
l Simple matches l Escape Sequences l Character classes l Metacharacters
l predefined classes l word boundaries l iterators l alternatives l subexpressions l backreferences Introduction Regular Expressions are a widely-used method of specifying patterns of text to search for. Special metacharacters allow You to specify, for instance, that a particular string You are looking for occurs at the beginning or end of a line, or contains n recurrences of a certain character. Regular expressions look ugly for novices, but really they are very simple (well, usually simple ;) ), handly and powerfull tool. I strongly recommend You to play with regular expressions using the learning application (199kb) - it'll help you to understand main conceptions. Let's start our learning trip! [ Top ] Simple matches Any single character matches itself, unless it is a metacharacter with a special meaning described below. A series of characters matches that series of characters in the target string, so the pattern "bluh" would match "bluh'' in the target string. Quite simple, eh ? You can cause characters that normally function as metacharacters or escape sequences to be interpreted literally by 'escaping' them by preceding them with a backslash "\", for instance: metacharacter "^" match beginning of string, but "\^" match character "^", "\\" match "\" and so on.
Escape sequences Characters may be specified using a escape sequences syntax much like that used in C and Perl: "\n'' matches a newline, "\t'' a tab, etc. More generally, \xnn, where nn is a string of hexadecimal digits, matches the character whose ASCII value is nn. If You need wide (Unicode) character code, You can use '\x{nnnn}', where 'nnnn' - one or more hexadecimal digits.
Character classes You can specify a character class, by enclosing a list of characters in [], which will match any one character from the list. If the first character after the "['' is "^'', the class matches any character not in the list.
If You want "-'' itself to be a member of a class, put it at the start or end of the list, or escape it with a backslash. If You want ']' you may place it at the start of list or escape it with a backslash.
Metacharacters Metacharacters are special characters which are the essence of Regular Expressions. There are different types of metacharacters, described below. [ Top ] line separators
The \A and \Z are just like "^'' and "$'', while "^'' and "$'' will match at every internal line separator. The ".'' metacharacter by default matches any character. [ Top ] predefined classes
word boundaries
[ Top ] iterators Any item of a regular expression may be followed by another type of metacharacters - iterators. Using this metacharacters You can specify number of occurences of previous character, metacharacter or subexpression.
If a curly bracket occurs in any other context, it is treated as a regular character.
[ Top ] alternatives You can specify a series of alternatives for a pattern using "|'' to separate them, so that fee|fie|foe will match any of "fee'', "fie'', or "foe'' in the target string (as would f(e|i|o)e). The first alternative includes everything from the last pattern delimiter ("('', "['', or the beginning of the pattern) up to the first "|'', and the last alternative contains everything from the last "|'' to the next pattern delimiter. For this reason, it's common practice to include alternatives in parentheses, to minimize confusion about where they start and end. Alternatives are tried from left to right, so the first alternative found for which the entire expression matches, is the one that is chosen. This means that alternatives are not necessarily greedy. For example: when matching foo|foot against "barefoot'', only the "foo'' part will match, as that is the first alternative tried, and it successfully matches the target string. (This might not seem important, but it is important when you are capturing matched text using parentheses.) Also remember that "|'' is interpreted as a literal within square brackets, so if You write [fee|fie|foe] You're really only matching [feio|].
subexpressions The bracketing construct ( ... ) may also be used for define r.e. subexpressions. Subexpressions are numbered based on the left to right order of their opening parenthesis. First subexpression has number '1' (whole r.e. match has number '0' - You can substitute it as '$0' or '$&').
backreferences Metacharacters \1 through \9 are interpreted as backreferences. \
Perl Extensions (?imsxr-imsxr) You may use it into r.e. for modifying modifiers by the fly. If this construction inlined into subexpression, then it effects only into this subexpression.
|