Method Reference: string.matches

string: TF = matches (str, pattern)
string: TF = matches (str, pattern, 'IgnoreCase', true)

Test if strings match pattern.

TF = matches (str, pattern) returns a logical array TF of the same size as A containing true for each corresponding element of str that matches the specified pattern and false otherwise. Similarly to NaN values, <missing> elements do not match any pattern and always return false.

TF = matches (str, pattern, 'IgnoreCase', true) ignores case when determining if str starts with pattern.

Source Code: string

Example: 1

matches tests, element-wise, whether each string equals a pattern exactly (contrast contains, which tests for a substring).

 s = string ({'cat'; 'category'; 'cat'})
s =
  3x1 string array

    "cat"         
    "category"    
    "cat"
 matches (s, 'cat')
ans =

  1
  0
  1