6MIB File Editor

The MIB file editor has the usual capabilities of a text editor including  undo and redo. The status bar displays row and column position of cursor. The table below the editor displays error messages from the integrated MIB compiler.

The annotation bar highlights the location of SMI syntax errors in the text. The text is rechecked at least one second after each change. During the update of the annotation bar the overall status on the top is gray.

The background validation of the text can be disabled using the Enable Background Validation toggle menu item of the editor‘s File menu.

6.1Save, Compile, and Load a MIB File at Once

By choosing Import MIB Import1600011.gif from the editor's File menu the edited file is saved, compiled, and loaded into the MIB tree. If compilation fails, then the edited MIB module(s) will not be imported into MIB Explorer. Instead an error text will be displayed in the text area below the editor's tool bar. On successful compilation, the MIB module(s) are stored in the MIB Repository and loaded and the editor window gets closed.

6.2Search and Replace Function

A powerful way to make modifications to a MIB file is searching and replacing by regular expressions.

To search a MIB file by a regular expression, choose Find Find16.gif from the Edit menu. Enter the expression to search for in the opened dialog. The combo box will remember ten expressions used last.

To search and replace found matches, choose Replace Replace16.gif from the Edit menu. Enter the search expression and the substitution expression and press OK.

The first matched region in the MIB file will be selected and a confirmation dialog for the replacement operation will be shown. Each substitution can be confirmed individually or all substitutions can be confirmed at once.

The substitution string may contain variable interpolations referring to the saved parenthesized groups of the search pattern. A variable interpolation is denoted by $1, or $2, or $3, etc. It is easiest to explain what an interpolated variable does by giving an example:

Suppose you have the pattern b\d+: and you want to substitute the b's for a's and the colon for a dash in parts of your input matching the pattern. You can do this by changing the pattern to b(\d+): and using the substitution expression a$1-. When a substitution is made, the $1 means „Substitute whatever was matched by the first saved group of the matching pattern“. An input of b123: after substitution would yield a result of a123-.

6.3Regular Expression Syntax

A regular expression (or RE) specifies a set of strings that matches it. Thus, a regular expression can be used to check whether an input string is matched by that expression.

Regular expressions can be concatenated to form new regular expressions; if A and B are both regular expressions, then AB is also a regular expression. If a string p matches A and another string q matches B, the string pq will match AB. Thus, complex expressions can easily be constructed from simpler primitive expressions like the ones described here.

A brief explanation of the format of regular expressions borrowed from the Python Library Reference follows.

Regular expressions can contain both special and ordinary characters. Most ordinary characters, like A, a, or 0, are the simplest regular expressions; they simply match themselves. You can concatenate ordinary characters, so last matches the string 'last'. (In the rest of this section, we will write RE's in this special style, usually without quotes, and strings to be matched 'in single quotes'.

Some characters, like "|" or "(", are special. Special characters either stand for classes of ordinary characters, or affect how the regular expressions around them are interpreted.

The special characters are shown by Table 3 on page 32:.

Table 3: Regular expression syntax characters with special meaning.

Expression

Description

.

(Dot.) In the default mode, this matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline.

^

(Caret.) Matches the start of the string, and in MULTILINE mode also matches immediately after each newline.

$

Matches the end of the string and in MULTILINE mode also matches before a newline. foo matches both 'foo' and 'foobar', while the regular expression foo$ matches only 'foo'.

*

Causes the resulting RE to match 0 or more repetitions of the preceding RE, as many repetitions as are possible. ab* will match 'a', 'ab', or 'a' followed by any number of 'b' s.

+

Causes the resulting RE to match 1 or more repetitions of the preceding RE. ab+ will match 'a' followed by any non-zero number of 'b's; it will not match just 'a'.

?

Causes the resulting RE to match 0 or 1 repetitions of the preceding RE. ab? will match either 'a' or 'ab'.

*?,+?,??

The *, +, and ? qualifiers are all greedy; they match as much text as possible. Sometimes this behavior is not desired; if the RE <.*> is matched against '<H1>title</H1>', it will match the entire string, and not just '<H1>'. Adding ? after the qualifier makes it perform the match in non-greedy or minimal fashion; as few characters as possible will be matched. Using .*? in the previous expression will match only '<H1>'.

{m,n}

Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as many repetitions as possible. For example, a{3,5} will match from 3 to 5 a characters. Omitting n specifies an infinite upper bound; you can't omit m.

{m,n}?

Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as few repetitions as possible. This is the non-greedy version of the previous qualifier. For example, on the 6-character string 'aaaaaa', a{3,5} will match 5 a characters, while a{3,5}? will only match 3 characters.

\

Either escapes special characters (permitting you to match characters like *, ?, and so forth), or signals a special sequence; special sequences are discussed below.

[]

Used to indicate a set of characters. Characters can be listed individually, or a range of characters can be indicated by giving two characters and separating them by a "-". Special characters are not active inside sets. For example, [akm$] will match any of the characters "a", "k", "m", or "$"; [a-z] will match any lowercase letter, and [a-zA-Z0-9] matches any letter or digit. Character classes such as \w or \S (defined below) are also acceptable inside a range. If you want to include a "]" or a "-" inside a set, precede it with a backslash, or place it as the first character. The pattern []] will match ']', for example.

You can match the characters not within a range by complementing the set. This is indicated by including a "^" as the first character of the set; "^" elsewhere will simply match the "^" character. For example, [^5] will match any character except "5".

|

A|B, where A and B can be arbitrary REs, creates a regular expression that will match either A or B. This can be used inside groups (see below) as well. To match a literal "|", use \|, or enclose it inside a character class, as in [|].

(...)

Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group; the contents of a group can be retrieved after a match has been performed (for example in a substitution expression), and can be matched later in the string with the \number special sequence, described below. To match the literals "(" or "')", use \( or \), or enclose them inside a character class: [(] [)].

(?...)

This is an extension notation (a "?" following a "(" is not meaningful otherwise). The first character after the "?" determines what the meaning and further syntax of the construct is. Extensions usually do not create a new group; (?P<name>>...) is the only exception to this rule. Following are the currently supported extensions.

(?imsx)

(One or more letters from the set "i", "L", "m", "s", "x".) The group matches the empty string; the letters set the corresponding flags for the entire regular expression:

i - Do case-insensitive pattern matching.

m - Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.

s - Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.

 

The /s and /m modifiers both override the $* setting. That is, no matter what $* contains, /s without /m will force "^" to match only at the beginning of the string and "$" to match only at the end (or just before a newline at the end) of the string. Together, as /ms, they let the "." match any character whatsoever, while yet allowing "^" and "$" to match, respectively, just after and just before newlines within the string.

Extend your pattern's legibility by permitting whitespace and comments.

(?:...)

A non-grouping version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.

(?#...)

A comment; the contents of the parentheses are simply ignored.

(?=...)

Matches if ... matches next, but doesn't consume any of the string. This is called a look-ahead assertion. For example, Isaac(?=Asimov) will match 'Isaac' only if it's followed by 'Asimov'.

(?!...)

Matches if ... does not match next. This is a negative look-ahead assertion. For example, Isaac (?!Asimov) will match 'Isaac' only if it's not followed by 'Asimov'.