User guide

24-12
SystemVerilog Testbench Constructs
Predefined String Methods
SystemVerilog provides several class methods to match patterns
within strings.
search()
The search() method searches for a pattern in the string and returns
the index number to the beginning of the pattern. If the pattern is not
found, then the function returns -1. The syntax is:
integer string_variable.search(string pattern);
Here, the argument must be a string.
The following example illustrates the usage of the search( ) class
method.
integer i;
string str = "SystemVerilog supports search( ) method";
i = str.search("supports");
printf("%d \n", i);
This example assigns the index 14 to integer i and prints out 14.
match()
The match() method processes a regular expression pattern match.
It returns 1 if the pattern is found else, it returns 0 if the pattern is not
found. The syntax is:
integer string_variable.match(string pattern);
Here, the pattern must be a regular Perl expression.
The following example illustrates the usage of the match() class
method.