G.4 Tips on using regular expressions
-
To use extended regular expressions by extending JP1-specific regular expressions (Windows) or POSIX1003.2 basic regular expressions (Linux), you must review the existing settings and redefine them to comply with the extended regular expressions, so as to avoid unintended behavior.
-
Control codes (linefeed codes, tab characters, and so on) might be handled differently depending on the product and operating system. For this reason, you should not include control codes in a regular expression used to specify a condition for a message.
-
A period followed by an asterisk (.*) matches any character. If you make frequent use of this regular expression, it might take a long time to find matches. When defining a condition to match a long message, for example, use the period-and-asterisk combination only where required in the search string.
In an environment that supports extended regular expressions, you can use the combination [^ ]* instead of the period-and-asterisk combination to match non-null characters. This reduces the search time.
-
When the regular expression ".*" is used for a condition of partial match, the condition is the same regardless of whether ".*" is specified at the beginning and end of the condition.
For example, examples 1 and 2 below specify the same condition.
- (Example 1) Regular expression that matches the character string that includes A001 Δ:ΔWeb server.
-
.*A001Δ:ΔWeb server.*
- (Example 2) Regular expression that matches the character string that includes A001Δ:ΔWeb server.
-
A001Δ:ΔWeb server
Therefore, do not specify ".*" at the beginning and end of the string, as it might increase the search time.
The regular expressions in the definition files shown below are designed to look for a complete match. The entire string being compared is examined, and the condition is satisfied only when a complete match is confirmed.
Note that, in this case, the search results will differ depending on whether ".*" is specified at the beginning and end of the string.
-
Event guide information file (jco_guide.txt)#
-
Intelligent Integrated Management Base definition file (imdd.properties)
-
System node definition file (imdd_systemnode.conf)
#: By default, regular expressions are designed to look for a complete match. However, you can configure regular expression to look for a partial match. For details about how to configure regular expressions in the event guide information file, see Event guide information file (jco_guide.txt) in Chapter 2. Definition Files in the manual JP1/Integrated Management 3 - Manager Command, Definition File and API Reference.
-
The vertical bar (|) represents an OR condition. Note the following when using this OR condition in a regular expression:
Because a vertical bar (|) has low precedence in a regular expression, you must specify the range of the OR condition explicitly; otherwise, it might work erroneously or not at all. You can specify the range of an OR condition by enclosing it in parentheses. An example of specifying the conditions for a source event server name as an OR condition is shown below.
- Example: JP1 events issued by work or host
-
^.*Δ.*Δ.*Δ.* Δ.*Δ(work|host)Δ.*Δ.*Δ.*Δ.*$
-
Spaces before or after the vertical bar (|) special character are treated as characters. Do not enter a space unless you want it to be included in the OR condition.
-
When an extended regular expression is used, if square brackets ([]), curly brackets ({}), or parentheses (()) are not properly paired, a syntax error occurs. If you want to use a square bracket, curly bracket, or parenthesis as an ordinary character, place a backslash (\) immediately before the character so that the character is not used as a special character.
The following shows an example of this case:
- Example: When you want to use a left parenthesis (() as an ordinary character:
-
\(
-
When using special characters, check the operation and make sure that regular expressions operate as expected. Checking the operation can prevent specification errors such as in the following example.
Example: Specifying a vertical bar (|) at the beginning or ending of a condition causes the condition to unexpectedly match all character strings.