ExpandCharacterClass - Maple Help

StringTools

 ExpandCharacterClass
 expand a character class to a string

 Calling Sequence ExpandCharacterClass( ccl )

Parameters

 ccl - string; character class expression

Description

 • The ExpandCharacterClass(ccl) command expands character class expressions as described in the following section. These expressions are used to describe sets of characters in wildcard and regular expression patterns, but may be used for other purposes as well.
 • If the string ccl is a valid character class expression, then a string, with at most 255 characters, is returned that denotes literally the expressed character class.

Character Classes

 In a character class expression, most characters denote themselves literally. For example, the character class expression $"abc"$ denotes the character class consisting of the characters $"a"$, $"b"$ and $"c"$, which is represented by the string $"abc"$. Likewise, the string $"bca"$, interpreted as a character class expression, denotes the character class $"abc"$, the only difference being the order in which the characters are presented. By convention, literal character classes are returned in code point order.
 If a character in a character class expression is preceded by a backslash, it is escaped, meaning that any special significance attached to it for character class expressions is suppressed (for that specific instance in the expression only).
 The first and last characters in a character class expression can be open and close brackets ($"\left["$ and $"\right]"$), respectively. In this case, the expression is equivalent to the one obtained by removing the first and last characters. If either of the characters $"\left["$ and $"\right]"$ appear anywhere but at the beginning and end, respectively, of the character class expression, they are taken literally. For example, $"\left[ab\right]de\right]"$ is equivalent to $"ab\right]de"$.

Character Ranges

 A consecutive range of characters is denoted by an interposed hyphen ($"-"$). For example, $"a-d"$ represents the character class $"abcd"$. The character to the left of the hyphen must precede the character to its right, in code point order. Thus, for example, $"z-a"$ is invalid.
 Character literals and ranges may be juxtaposed in a character class expression. For example, $"a-cwxyzd-h"$ is a valid character class expression which expands to the literal character class $"abcdefghwxyz"$.

Negated Character Classes

 If the first character in a character class expression is a caret ($"^"$) (or, if the character class expression is enclosed in brackets, and the caret follows the opening bracket), then the resulting character class is negated. This means that the character class expression expands to the set of characters not in the class described by the rest of the expression.

Named Character Classes

 If the first and last characters of a character class expression are colons ($":"$), the character between them are taken to form the name of a named character class. Such an expression expands to the literal character class denoted by the named class.
 The following named character classes are recognized.

 alpha alphabetic characters alnum alphabetic characters and digits ascii ASCII (7-bit) characters binary "0" and "1" cntrl control characters digit decimal digits hdigit hexadecimal digits (both cases) ident identifier characters ident1 leading identifier characters lower lowercase letters odigit octal digits (0-7) space whitespace characters upper uppercase letters vowel vowels (both cases)

 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{ExpandCharacterClass}\left("abc"\right)$
 ${"abc"}$ (1)
 > $\mathrm{ExpandCharacterClass}\left("bca"\right)$
 ${"abc"}$ (2)
 > $\mathrm{ExpandCharacterClass}\left(""\right)$
 ${""}$ (3)
 > $\mathrm{ExpandCharacterClass}\left("a-z"\right)$
 ${"abcdefghijklmnopqrstuvwxyz"}$ (4)
 > $\mathrm{ExpandCharacterClass}\left("a-z123"\right)$
 ${"123abcdefghijklmnopqrstuvwxyz"}$ (5)
 > $\mathrm{ExpandCharacterClass}\left("\left[a-z123\right]"\right)$
 ${"123abcdefghijklmnopqrstuvwxyz"}$ (6)
 > $\mathrm{ExpandCharacterClass}\left("a-ce-h"\right)$
 ${"abcefgh"}$ (7)
 > $\mathrm{ExpandCharacterClass}\left("a-cwxyzd-h"\right)$
 ${"abcdefghwxyz"}$ (8)
 > $\mathrm{ExpandCharacterClass}\left(":vowel:"\right)$
 ${"AEIOUaeiou"}$ (9)
 > $\mathrm{ExpandCharacterClass}\left(":binary:"\right)$
 ${"01"}$ (10)
 > $\mathrm{ExpandCharacterClass}\left(":digit:"\right)$
 ${"0123456789"}$ (11)
 > $\mathrm{ExpandCharacterClass}\left(":digit:"\right)$
 ${"0123456789"}$ (12)
 > $\mathrm{Visible}\left(\mathrm{ExpandCharacterClass}\left("^a-zA-Z"\right)\right)$
 ${"\1\2\3\4\5\6\7\8\9\10\11\12\13\14\15\16\17\18\19\20\21\22\23\24\25\26\27\28\29\30\31 !"#%\text{'}\left(\right)*+,-./0123456789:<=>?@\left[\\right]^_\left\{|\right\}~\127\128\129\130\131\132\133\134\135\136\137\138\139\140\141\142\143\144\145\146\147\148\149\150\151\152\153\154\155\156\157\158\159\160\161\162\163\164\165\166\167\168\169\170\171\172\173\174\175\176\177\178\179\180\181\182\183\184\185\186\187\188\189\190\191\192\193\194\195\196\197\198\199\200\201\202\203\204\205\206\207\208\209\210\211\212\213\214\215\216\217\218\219\220\221\222\223\224\225\226\227\228\229\230\231\232\233\234\235\236\237\238\239\240\241\242\243\244\245\246\247\248\249\250\251\252\253\254\255"}$ (13)
 > ExpandCharacterClass( cat( "^", Iota( 1, 32 ), Iota( 120, 255 ) ) );
 ${"!"#%\text{'}\left(\right)*+,-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\left[\\right]^_abcdefghijklmnopqrstuvw"}$ (14)