characterListPattern

Pattern that matches any single character from a list.

Category: Language Fundamentals > Data Types

Syntax

pat = characterListPattern(chars)

Matches one character found in chars.

Description

It plays the role of a bracket expression [...] in regular expressions, but without special symbols: every character in chars is taken literally, including - and ^. Combine it with asManyOfPattern to match runs of such characters.

Input arguments

chars
Text whose characters form the list.

Output arguments

pat
A pattern object matching one character.

Example

Separators in text

extract('a-b_c', characterListPattern('-_'))
extract('a1b2', characterListPattern('0123456789'))
Output
ans = 2×1 string array

    "-"
    "_"
ans = 2×1 string array

    "1"
    "2"

See also

digitsPattern lettersPattern asManyOfPattern extract pattern