A string match is a match to one or more characters. An example of a string match is:

RULE {
 “def”
}

If the “def” pattern is compared with an input string of “defdefeedef,” the rule matches twice and fails when it reaches the “eedef.”

In the following script, the pattern used for matching is def. The pattern matches def twice and fails with the input of eed. When the pattern fails in this script, the DEFAULT rule runs, which matches the entire line.

In most of the examples in this chapter, the pattern to match is surrounded by the following, which assigns the matched data to the variable a:

a:{
}

The section “Assignment operator” on page 47 provides additional information.

It is not necessary to include a variable assignment as part of pattern matching. The matched data is printed by printing the contents of the variable a.

ASL Script (str_match.asl):
START {
 a:{
 "def"}
}
do {
 print("Matched with ".a);
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
}
Input (str_match.txt):
defdefead
Output:
$ sm_adapter --file=str_match.txt str_match.asl
Matched with def
Matched with def
Failed match
$ 

The match for some characters requires a special syntax. Match syntax for special characters contains the special characters:

Table 1. Match syntax for special characters

Character

Syntax

Notes

tab

\t

single quotation mark (')

\'

The quotation marks surrounding the string that contains this code must be double quotes.

double quotation mark (")

\"

The quotation marks surrounding the string that contains this code must be single quotes.

backward slash (\)

\\

carriage return

\r

In most cases, use the eol pattern match instead of carriage return. “End-of-line matches” on page 58 provides additional information.

line feed

\n

In most cases, use the eol pattern match instead of line feed. “End-of-line matches” on page 58 provides additional information.

Note:

Pattern matches are by default case-sensitive. “Making patterns case-sensitive or case-insensitive” on page 68 discusses how to override the default.