Main Content

caseSensitivePattern

Match pattern with case sensitivity

Since R2020b

Description

example

newpat = caseSensitivePattern(pat) creates a pattern that matches pat using case-sensitive matching.

Examples

collapse all

Use caseSensitivePattern to enforce case sensitivity in case-insensitive functions.

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

txt = "abc";
pat = "ABC";
contains(txt,pat,'IgnoreCase',true)
ans = logical
   1

Use caseSensitivePattern to enforce case-sensitivity in matching for pat even when used as the input for a case-insensitive function.

pat = caseSensitivePattern(pat);
contains(txt,pat,'IgnoreCase',true)
ans = logical
   0

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.

Algorithms

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.

Version History

Introduced in R2020b