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
|
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 |
|
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
Comments
Log in or register to comment.