# strmatch

(Not recommended) Find possible matches for string

`strmatch` is not recommended. Use another function depending on your goal. To determine which array elements begin with specified text, use `startsWith` or `strncmp`. To find the best match for specified text, use `validatestring`. To find an exact match for specified text, use `matches`.

## Syntax

``x = strmatch(str, strarray)``
``x = strmatch(str, strarray, 'exact')``

## Description

````x = strmatch(str, strarray)` looks through the rows of the text array `strarray` to find elements that begin with the text contained in `str`. If `strmatch` does not find `str` in `strarray`, then `x` is an empty matrix (`[]`). Any trailing whitespace characters in `str` or `strarray` are ignored when matching. `strmatch` is fastest when `strarray` is a character array.```

example

````x = strmatch(str, strarray, 'exact')` compares `str` with each row of `strarray`, looking for an exact match of the entire character vector. Any trailing space characters in `str` or `strarray` are ignored when matching.```

## Examples

collapse all

Create a string array. Use `strmatch` to find elements of `strarray` that begin with the text `"max"`.

```strarray = ["max" "minimax" "maximum"]; x = strmatch("max", strarray)```
```x = 2×1 1 3 ```

Create a string array. Use `strmatch` with the third input `"exact"` to find elements of `strarray` that exactly match the text `"max"`.

```strarray = ["max" "minimax" "maximum"]; x = strmatch("max",strarray,"exact")```
```x = 1 ```

## Input Arguments

collapse all

Pattern text, specified as a character vector, string scalar, or cell array of character vectors.

Data Types: `char` | `string` | `cell`

Text array, specified as a character array, string array, or cell array of character vectors.

Data Types: `char` | `string` | `cell`

## Version History

Introduced before R2006a