caseInsensitivePattern

Pattern that ignores letter case when matching.

Category: Language Fundamentals > Data Types

Syntax

newPat = caseInsensitivePattern(pat)

Makes pat match regardless of case.

Description

Pattern matching is case sensitive by default. Wrapping a pattern in caseInsensitivePattern changes only that part, so it can be combined with case-sensitive parts through + or |.

It is an alternative to the 'IgnoreCase' option of functions such as contains and startsWith, useful when only one piece of a larger pattern should ignore case.

Input arguments

pat
A pattern or text.

Output arguments

newPat
A pattern object.

Example

Ignoring case

extract('abAB', caseInsensitivePattern('a'))
contains('ABC', caseInsensitivePattern('b'))
Output
ans = 2×1 string array

    "a"
    "A"
ans = logical
   1

See also

caseSensitivePattern contains startsWith pattern