Regular Expression Syntax
Kiwi Log Viewer supports the use of Perl Compatible Regular Expression (PCRE) matching. More information on PCRE syntax can be found at: http://www.pcre.org.
Pattern syntax
The following pattern syntax can be used:
| Pattern | Description |
|---|---|
.
|
Matches any character except new line |
[a-z0-9]
|
Matches any single character of set. |
[^a-z0-9]
|
Matches any single character not in set. |
\d
|
Matches a digit. Same as [0-9]. |
\D
|
Matches a non-digit. Same as [^0-9]. |
\w
|
Matches an alphanumeric (word) character -- [a-zA-Z0-9_]. |
\W
|
Matches a non-word character [^a-zA-Z0-9_]. |
\s
|
Matches a white space character (space, tab, new line, etc.). |
\S
|
Matches a non-white space character. |
\n
|
Matches a new line (line feed). |
\r
|
Matches a return. |
\t
|
Matches a tab. |
\f
|
Matches a form feed. |
\b
|
Matches a backspace. |
\0
|
Matches a null character. |
\000
|
Also matches a null character because of the following: |
\nnn
|
Matches an ASCII character of that octal value. |
\xnn
|
Matches an ASCII character of that hexadecimal value. |
\cX
|
Matches an ASCII control character. |
\metachar
|
Matches the meta-character (e.g., \, .,) |
(abc)
|
Used to create sub expressions. Remembers the match for later back references. Referenced by replacement patterns that use \1, \2, etc. |
\1, \2,...
|
Matches whatever first (second, and so on) of parens matched. |
x?
|
Matches 0 or 1 x's, where x is any of above. |
x*
|
Matches 0 or more x's. |
x+
|
Matches 1 or more x's. |
x{m,n}
|
Matches at least m x's, but no more than n. |
abc
|
Matches all of a, b, and c in order. |
\b
|
Matches a word boundary (outside [] only). |
\B
|
Matches a non-word boundary. |
^
|
Anchors match to the beginning of a line or string. |
$
|
Anchors match to the end of a line or string. |
Wildcards
Some special characters are used to match a class of characters.
| Wildcard | Matches |
|---|---|
.
|
Any single character except a line break, including a space |
The following wildcards match by position in a line:
| Wildcard | Matches | Example |
|---|---|---|
^
|
Beginning of a line (unless used in a character class; see below) | ^Phone: Finds lines that begin with "Phone:" |
$
|
End of a line (unless used in a character class) | $: Finds the last character in the current line. |
Character Classes
A character class allows you to specify a set or range of characters. You can choose to either match or ignore the character class. The set of characters is enclosed in brackets. If you want to ignore the character class instead of match it, precede it by a caret (^). Here are some examples:
| Character Class | Matches |
[aeiou]
|
Any one of the characters a, e, i, o, u. |
[^aeiou]
|
Any character except a, e, i, o, u. |
[a-e]
|
Any character in the range a-e, inclusive |
[a-zA-Z0-9]
|
Any alphanumeric character. |
[[]
|
Finds a [. |
[]]
|
Finds a ]. To find a closing bracket, place it immediately after the opening bracket. |
[a-e^]
|
Finds a character in the range a-e or the caret character. To find the caret character, place it anywhere except as the first character after the opening bracket. |
[a-c-]
|
Finds a character in the range a-c or the - sign. To match a -, place it at the beginning or end of the set. |
Non-printing Characters
You can use the following notation to find non-printing characters:
| Special Character | Matches |
|---|---|
\r
|
Line break (return) |
\n
|
New line (line feed) |
\t
|
Tab |
\f
|
Form feed (page break) |
\xNN
|
Hex code NN. |
Other Special Characters
The following patterns are wildcards for the following special characters:
| Special Character | Matches |
|---|---|
\s
|
Any white space character (space, tab, return, linefeed, form feed) |
\S
|
Any non-white space character. |
\w
|
Any "word" character (a-z, A-Z, 0-9, and _) |
\W
|
Any "non-word" character (All characters not included by \w). |
\d
|
Any digit [0-9]. |
\D
|
Any non-digit character. |
Repetition Characters
Repetition characters are modifiers that allow you to repeat a specified pattern.
| Repetition Character | Matches | Examples |
|---|---|---|
*
|
Zero or more characters. |
|
+
|
One or more characters. |
|
?
|
Zero or one characters. | d? finds no characters or one "d". |
Please note that, since * and ? match zero instances of the pattern, they always succeed but may not select any text. You can use them to specify an optional character, as in the examples in the following section.
Extension Mechanism
| (?#text) | Comment |
|---|---|
(?:pattern)
|
For grouping without creating back references |
(?=pattern)
|
A zero-width positive look-ahead assertion. For example, \w+(?= ) matches a word followed by a tab, without including the tab in $& |
(?!pattern)
|
A zero-width negative look-ahead assertion. For example foo(?!bar) matches any occurrence of "foo" that isn't followed by "bar". |
(?<=pattern)
|
A zero-width positive look-behind assertion. For example, (?<= )\w+ matches a word that follows a tab, without including the tab in $&. Works only for fixed-width look- behind. |
(?<!pattern)
|
A zero-width negative look-behind assertion. For example (?<!bar)foo matches any occurrence of "foo" that does not follow "bar". Works only for fixed-width look- behind. |
The Alternation Operator
The alternation operator of pipe (|) allows you to match any of a number of patterns using the logical "or" operator. Place it between two existing patterns to match either pattern. You can use more than one alternation operator in a pattern. eg. cat|dog|fish will match cat or dog or fish.
Examples
To match Address1 OR Address2, use: (126\.34\.55\.1)|(123\.45\.67\.89)
To match Address1 AND Address2, use: (126\.34\.55\.1).*(123\.45\.67\.89)