Main Content


Match pattern regardless of case



newpat = caseInsensitivePattern(pat) creates a pattern that matches pat regardless of case.


collapse all

Use caseInsensitivePattern to match text regardless of whether the text is upper-case or lower-case.

Create txt as a string with "abc" repeated in a mixture of upper- and lower-case. Create a pattern, pat, that matches the literal "abc". Extract the pattern.

txt = "abc ABC AbC";
pat = "abc";
ans = 

Make pat case insensitive using caseInsensitivePattern. Extract the new pattern.

pat = caseInsensitivePattern(pat);
ans = 3x1 string

Use caseInsensitivePattern to enforce case insensitivity in case-sensitive functions.

Create a string of lowercase letters. Create a pattern that matches uppercase "ABC". When used in a case-sensitive function, pat does not match txt.

txt = "abc";
pat = "ABC";
ans = logical

Use caseInsensitivePattern to enforce case insensitivity in matching for pat even when used as the input for a case-sensitive function.

pat = caseInsensitivePattern(pat);
ans = logical

Input Arguments

collapse all

Input pattern, specified as a pattern, string array, character vector, or cell array of character vectors.

Data Types: char | string | pattern | cell

Output Arguments

collapse all

Output pattern, returned as a pattern or an array of pattern objects.


When caseInsensitivePattern and caseSensitivePattern are used as inputs for one another, the behavior of the input pattern overrules the outer function. For example, caseInsensitivePattern(caseSensitivePattern(pat)) behaves case sensitively.

Introduced in R2020b