Occasionally, you may want to match a string that is explicitly at the front or back end of a line. You can do this by adding the special characters to the expression to mark the location of the start of the line or the end of the line. You can also align the pattern with word boundaries as well. Here is a summary of some special patterns that are position aligned:
Pattern | Description |
---|---|
^ | Indicate the start of the line |
$ | Indicate the end of the line |
\b | Indicate a word boundary. Note that this cannot be used in a bracketed character class [\b] means backspace not word boundary |
\B | Indicate any non-word boundary location. |
.$ | The last character at the end of the line (the dot matches one character) |
\b\d*\b | A complete word composed only of numeric digits |
\b\w*\b | A complete word |
\s*$ | All of the trailing whitespace. |
^$ | A line with nothing between the start and end, an empty line. |
^. | The first character at the beginning of the line (the dot matches one character) |
^.*$ | The entire line regardless of its contents. |
^\s | A leading whitespace character. |
In multi-line mode, the markers for the start and end of the line apply to each line in turn.
Prev | Home | Next |
RegExp pattern - grouping | Up | RegExp pattern - references |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |