Next: Color syntax highlighting Up: Using Smac Previous: C-C++ headers

# Regular expressions

A regular expression (regexp) is a text string that describes some set of strings.

Functions that handle regular expressions, based on GNU regexp-0.12, have been implemented (for more details, see the GNU documentation about regexp rules).

The functions available from Search menu provide search forward or backward and replace. Each of them prompts a dialog box to get the target regexp.

Regular expressions are composed of characters and operators that match one or more characters. Here is an abstract of commons operators:

- . matches any single character.
- * repeats the smallest possible preceding regular expression as many times as necessary (including zero).

- + is similar to the previous operator except that it repeats the preceding regular expression at least once.

- ? is similar to the * operator except that it repeats the preceding regular expression once or not at all.

- `|` matches one of a choice of regular expressions.

- `[...]` matches one item of a list.

- `[^...]` matches a single character not represented by one of the list items.

- - recognizes characters that fall between two elements.

- `(...)` treats any number of other operators (i.e. subexpressions) as a unit.

- `\`digit matches a specified preceding group.

- `^` matches the beginning of line.

- `$` matches the end of line.

Smac provides the following functions:

- int re_forward_search(char *regexp);

  returns the position of the next regular expression regexp, or -1 if regexp has not been found, or -2 if regexp is not valid.

- int re_backward_search(char *regexp);

  returns the position of the previous regular expression regexp, or -1 if regexp has not been found, or -2 if regexp is not valid.

- int re_match_beginning(int n);

  returns the beginning position of the substring n of the regexp found by the previous search call to a regexp.

- int re_match_end(int n);

  returns the end position of the substring n of the regexp found by the previous search call to a regexp.

- int re_replace(char *newstring [,char *regexp]);

  replaces the regular expression regexp with the string newstring. If the argument regexp is omited, the previous search call to a regexp is used. It returns 1 on success else 0.

Example:

Next: Color syntax highlighting Up: Using Smac Previous: C-C++ headers