matchline()

Compare text to a regular-expression and save the result to user-defined variables.

Syntax

matchline(text,regular_expression,[t],variable_1,[variable_2,... variable_9])

Parameter

Parameter

Definition

Parameter

Definition

text

text to compare to the regular expression

regularexpression_

character sequence that defines the pattern that the matchline() function searches for in text Theregular_expression conforms to the regular expressions defined in the Unix ed(1) command and the Unix regexp(5) description. The following is a brief summary of several regular expression characters:
^ beginning of line 
$ end of line 
. match any single character 
* match zero or more repetitions of the preceding 
[] match any of the characters contained within 
[^] match any characters except those contained within 
\< match any characters at the beginning of a word 
\> match any characters at the end of a word 
Word boundaries are delimited by any characters other than the following:

  • A through Z
  • a through z
  • 0 through 9
  • _

t

optional flag that causes matchline() to return the number of fields that can be saved to variables If you use this flag, you can compare the number returned by matchline() to the actual number of fields saved to variables.

variable_1 [...variable_9]

one or more user-defined variables You can use a maximum of nine variables. Declare and initialize variables before using them to call matchline().

Description

The matchline() function compares text to a regular-expression and saves the result to one or more user-defined variables. 

Typically this function returns the number of fields that it successfully saves to variables. You can use this number to determine how many of the variables, used to call matchline(), contain useful information. With the t flag, matchline() returns the number of fields in text that match the regular-expression. You can use this number to determine whether you called matchline() with enough variables to capture all matching fields. 

This function returns NULL when it encounters an error, and it assigns the following value to the errno variable. 

errno Value

Description of Failure

44


E_PSL_GREP_BAD_REGEXP 
The regular-expression contains one or more errors.

Example

The following example demonstrates the matchline() function:

errno=0;
input="abcAAdef";
regrep="\\([a-c]+\\)AA\\([d-f]+\\)";
text_var=" ";
text_var2=" ";
ret= matchline(input,regrep,"",text_var);
print("Matchline with no flag and one variable:\n");
print("Return=".ret." errno=".errno." Text Variable=".text_var."\n");
print("\nMatchline with t flag and one variable:\n");
ret= matchline(input,regrep,"t",text_var);
print("Return=".ret." errno=".errno." Text Variable=".text_var."\n");
print("\nMatchline with t flag and two variables:\n");
ret= matchline(input,regrep,"t",text_var,text_var2);
print("Return=".ret." errno=".errno." Variable=".text_var." Variable 2=".text_var2);

The following output results from the preceding example: 

Matchline with no flag and one variable:
Return=1 errno=0 Text Variable=abc
Matchline with t flag and one variable:
Return=2 errno=0 Text Variable=abc
Matchline with t flag and two variables:
Return=2 errno=0 Variable=abc Variable 2=def

Was this page helpful? Yes No Submitting... Thank you

Comments