Browse
When you type a search term surrounded by "quote marks" into the search box on NLT.to, the results match whatever occurs between the quotes. In this case, match means POSIX extended regular expression match. Here we document the details of how to use it to your full advantage in searching the NLT text.
Our regular expression matching is case-insensitive. So you can type "run", and youll get results that also match Run.
The POSIX regular expression matching engine in this site uses a software package written by Henry Spencer. Much of the description of regular expressions below is copied verbatim from his manual.
A regular expression is defined as one or more branches, separated by |. It matches anything that matches one of the branches.
A branch is zero or more quantified atoms or constraints, concatenated. It matches a match for the first, followed by a match for the second, etc; an empty branch matches the empty string.
A quantified atom is an atom possibly followed by a single quantifier. Without a quantifier, it matches a match for the atom. With a quantifier, it can match some number of matches of the atom. An atom can be any of the possibilities shown in Table 1. The possible quantifiers and their meanings are shown in Table 2.
A constraint matches an empty string, but matches only when specific conditions are met. A constraint can be used where an atom could be used, except it cannot be followed by a quantifier. The simple constraints are shown in Table 3; some more constraints are described later.
| Atom | Description |
| . | matches any single character |
| [chars] | a bracket expression, matching any one of the chars (see Bracket Expressions, below, for more detail) |
| \k | (where k is a non-alphanumeric character) matches that character taken as an ordinary character, e.g., \\ matches a backslash character |
| \c | where c is alphanumeric (possibly followed by other characters) is an escape, see Regular Expression Escapes, below. |
| { | when followed by a character other than a digit, matches the left-brace character {; when followed by a digit, it is the beginning of a bound (see below) |
| x | where x is a single character with no other significance, matches that character |
| Quantifier | Matches |
| * | a sequence of 0 or more matches of the atom |
| + | a sequence of 1 or more matches of the atom |
| ? | a sequence of 0 or 1 matches of the atom |
| {m} | a sequence of exactly m matches of the atom |
| {m,} | a sequence of m or more matches of the atom |
| {m,n} | a sequence of m through n (inclusive) matches of the atom; m cannot exceed n |
| *? | non-greedy version of * |
| +? | non-greedy version of + |
| ?? | non-greedy version of ? |
| {m}? | non-greedy version of {m} |
| {m,}? | non-greedy version of {m,} |
| {m,n}? | non-greedy version of {m,n} |
The forms using {...} are known as bounds. The numbers m and n within a bound are unsigned decimal integers with permissible values from 0 to 255 inclusive.
Non-greedy quantifiers (available in AREs only) match the same possibilities as their corresponding normal (greedy) counterparts, but prefer the smallest number rather than the largest number of matches. See Regular Expression Matching Rules, below, for more detail.
Note: A quantifier cannot immediately follow another quantifier, e.g., ** is invalid. A quantifier cannot begin an expression or subexpression or follow ^ or |.
| Constraint | Description |
| ^ | matches at the beginning of the string |
| $ | matches at the end of the string |
| (?=re) | positive lookahead matches at any point where a substring matching re begins (AREs only) |
| (?!re) | negative lookahead matches at any point where no substring matching re begins (AREs only) |
A bracket expression is a list of characters enclosed in []. It normally matches any single character from the list (but see below). If the list begins with ^, it matches any single character not from the rest of the list. If two characters in the list are separated by -, this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, e.g., [0-9] in ASCII matches any decimal digit. It is illegal for two ranges to share an endpoint, e.g., a-c-e. Ranges are very collating-sequence-dependent, so portable programs should avoid relying on them.
To include a literal ] in the list, make it the first character (after ^, if that is used). To include a literal -, make it the first or last character, or the second endpoint of a range. To use a literal - as the first endpoint of a range, enclose it in [. and .] to make it a collating element (see below). With the exception of these characters, some combinations using [ (see next paragraphs), and escapes, all other special characters lose their special significance within a bracket expression. In particular, \ is special (as introducing an escape).
Within a bracket expression, a collating element enclosed in [= and =] is an equivalence class, standing for the sequences of characters of all collating elements equivalent to that one, including itself. (If there are no other equivalent collating elements, the treatment is as if the enclosing delimiters were [. and .].) For example, if o and ^ are the members of an equivalence class, then [[=o=]], [[=^=]], and [o^] are all synonymous. An equivalence class cannot be an endpoint of a range.
Within a bracket expression, the name of a character class enclosed in [: and :] stands for the list of all characters belonging to that class. Standard character class names are: alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit. These stand for the character classes. A character class cannot be used as an endpoint of a range.
Escapes are special sequences beginning with \ followed by an alphanumeric character. Escapes come in several varieties: character entry, class shorthands, constraint escapes, and back references. A \ followed by an alphanumeric character not constituting a valid escape is illegal.
Character-entry escapes exist to make it easier to specify non-printing and other inconvenient characters in REs. They are shown in Table 4.
| Escape | Description |
| \a | alert (bell) character, as in C |
| \b | backspace, as in C |
| \B | synonym for backslash (\) to help reduce the need for backslash doubling |
| \cX | (where X is any character) the character whose low-order 5 bits are the same as those of X, and whose other bits are all zero |
| \e | the character whose collating-sequence name is ESC, or failing that, the character with octal value 033 |
| \f | form feed, as in C |
| \n | newline, as in C |
| \r | carriage return, as in C |
| \t | horizontal tab, as in C |
| \uwxyz | (where wxyz is exactly four hexadecimal digits) the UTF16 (Unicode, 16-bit) character U+wxyz in the local byte ordering |
| \Ustuvwxyz | (where stuvwxyz is exactly eight hexadecimal digits) reserved for a hypothetical Unicode extension to 32 bits |
| \v | vertical tab, as in C |
| \xhhh | (where hhh is any sequence of hexadecimal digits) the character whose hexadecimal value is 0xhhh (a single character no matter how many hexadecimal digits are used) |
| \0 | the character whose value is 0 (the null byte) |
| \xy | (where xy is exactly two octal digits, and is not a back reference) the character whose octal value is 0xy |
| \xyz | (where xyz is exactly three octal digits, and is not a back reference) the character whose octal value is 0xyz |
The character-entry escapes are always taken as ordinary characters. For example, \135 is ] in ASCII, but \135 does not terminate a bracket expression.
Class-shorthand escapes provide shorthands for certain commonly-used character classes. They are shown in Table 5.
| Escape | Description |
| \d | [[:digit:]] |
| \s | [[:space:]] |
| \w | [[:alnum:]_] (note underscore is included) |
| \D | [^[:digit:]] |
| \S | [^[:space:]] |
| \W | [^[:alnum:]_] (note underscore is included) |
Within bracket expressions, \d, \s, and \w lose their outer brackets, and \D, \S, and \W are illegal. (So, for example, [a-c\d] is equivalent to [a-c[:digit:]]. Also, [a-c\D], which is equivalent to [a-c^[:digit:]], is illegal.)
A constraint escape is a constraint, matching the empty string if specific conditions are met, written as an escape. They are shown in Table 6.
| Escape | Description |
| \A | matches only at the beginning of the string (see Regular Expression Matching Rules for how this differs from ^) |
| \m | matches only at the beginning of a word |
| \M | matches only at the end of a word |
| \y | matches only at the beginning or end of a word |
| \Y | matches only at a point that is not the beginning or end of a word |
| \Z | matches only at the end of the string (see Regular Expression Matching Rules for how this differs from $) |
| Escape | Description |
| \m | (where m is a nonzero digit) a back reference to the m'th subexpression |
| \mnn | (where m is a nonzero digit, and nn is some more digits, and the decimal value mnn is not greater than the number of closing capturing parentheses seen so far) a back reference to the mnn'th subexpression |
Note: There is an inherent ambiguity between octal character-entry escapes and back references, which is resolved by the following heuristics, as hinted at above. A leading zero always indicates an octal escape. A single non-zero digit, not followed by another digit, is always taken as a back reference. A multi-digit sequence not starting with a zero is taken as a back reference if it comes after a suitable subexpression (i.e., the number is in the legal range for a back reference), and otherwise is taken as octal.
In addition to the main syntax described above, there are some special forms and miscellaneous syntactic facilities available.
Normally the flavor of RE being used is determined by regex_flavor. However, this can be overridden by a director prefix. If an RE begins with ***:, the rest of the RE is taken as an ARE regardless of regex_flavor. If an RE begins with ***=, the rest of the RE is taken to be a literal string, with all characters considered ordinary characters.
An ARE can begin with embedded options: a sequence (?xyz) (where xyz is one or more alphabetic characters) specifies options affecting the rest of the RE. These options override any previously determined options (including both the RE flavor and case sensitivity). The available option letters are shown in Table 8.
| Option | Description |
| b | rest of RE is a BRE |
| c | case-sensitive matching (overrides operator type) |
| e | rest of RE is an ERE |
| i | case-insensitive matching (see Regular Expression Matching Rules) (overrides operator type) |
| m | historical synonym for n |
| n | newline-sensitive matching (see Regular Expression Matching Rules) |
| p | partial newline-sensitive matching (see Regular Expression Matching Rules) |
| q | rest of RE is a literal ("quoted") string, all ordinary characters |
| s | non-newline-sensitive matching (default) |
| t | tight syntax (default; see below) |
| w | inverse partial newline-sensitive ("weird") matching (see Regular Expression Matching Rules) |
| x | expanded syntax (see below) |
Embedded options take effect at the ) terminating the sequence.
In addition to the usual (tight) RE syntax, in which all characters are significant, there is an expanded syntax, available by specifying the embedded x option. In the expanded syntax, white-space characters in the RE are ignored, as are all characters between a # and the following newline (or the end of the RE). This permits paragraphing and commenting a complex RE. There are three exceptions to that basic rule:
For this purpose, white-space characters are blank, tab, newline, and any character that belongs to the space character class.
Finally, in an ARE, outside bracket expressions, the sequence (?#ttt) (where ttt is any text not containing a )) is a comment, completely ignored. Again, this is not allowed between the characters of multi-character symbols, like (?:. Such comments are more a historical artifact than a useful facility, and their use is deprecated; use the expanded syntax instead.
None of these metasyntax extensions is available if an initial ***= director has specified that the user's input be treated as a literal string rather than as an RE.
In the event that an RE could match more than one substring of a given string, the RE matches the one starting earliest in the string. If the RE could match more than one substring starting at that point, either the longest possible match or the shortest possible match will be taken, depending on whether the RE is greedy or non-greedy.
Whether an RE is greedy or not is determined by the following rules:
The above rules associate greediness attributes not only with individual quantified atoms, but with branches and entire REs that contain quantified atoms. What that means is that the matching is done in such a way that the branch, or whole RE, matches the longest or shortest possible substring as a whole. Once the length of the entire match is determined, the part of it that matches any particular subexpression is determined on the basis of the greediness attribute of that subexpression, with subexpressions starting earlier in the RE taking priority over ones starting later.
When an RE contains both greedy and non-greedy subexpressions, the total match length is either as long as possible or as short as possible, according to the attribute assigned to the whole RE. The attributes assigned to the subexpressions only affect how much of that match they are allowed to "eat" relative to each other.
The quantifiers {1,1} and {1,1}? can be used to force greediness or non-greediness, respectively, on a subexpression or a whole RE.
Match lengths are measured in characters, not collating elements. An empty string is considered longer than no match at all. For example: bb* matches the three middle characters of abbbc; (week|wee)(night|knights) matches all ten characters of weeknights; when (.*).* is matched against abc the parenthesized subexpression matches all three characters; and when (a*)* is matched against bc both the whole RE and the parenthesized subexpression match an empty string.
If case-independent matching is specified, the effect is much as if all case distinctions had vanished from the alphabet. When an alphabetic that exists in multiple cases appears as an ordinary character outside a bracket expression, it is effectively transformed into a bracket expression containing both cases, e.g., x becomes [xX]. When it appears inside a bracket expression, all case counterparts of it are added to the bracket expression, e.g., [x] becomes [xX] and [^x] becomes [^xX].
If newline-sensitive matching is specified, . and bracket expressions using ^ will never match the newline character (so that matches will never cross newlines unless the RE explicitly arranges it) and ^and $ will match the empty string after and before a newline respectively, in addition to matching at beginning and end of string respectively. But the ARE escapes \A and \Z continue to match beginning or end of string only.
If partial newline-sensitive matching is specified, this affects . and bracket expressions as with newline-sensitive matching, but not ^ and $.
If inverse partial newline-sensitive matching is specified, this affects ^ and $ as with newline-sensitive matching, but not . and bracket expressions. This isn't very useful but is provided for symmetry.