Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A bracket expression is a pattern matching construct enclosed in square brackets ([...]) that matches exactly one character from a specified set. Within a bracket expression, a character class specifically refers to a named, locale-aware set of characters enclosed in [: and :].

Literal Sets and Ranges

A standard bracket expression matches any single literal character listed within the brackets. Ranges define a contiguous sequence of characters using a hyphen (-), determined by the collating order of the current locale.
[abc]
[a-z]
[a-zA-Z0-9_]

Complementation (Negation)

A bracket expression is negated by placing an exclamation mark (!) or a caret (^) immediately after the opening bracket. This matches any single character not specified in the set. In standard Bash globbing, ! is the POSIX-compliant negation operator, while ^ is typically used in regular expression contexts.
[!abc]
[^0-9]

Character Classes

A character class is a predefined set of characters denoted by [:classname:]. Because character classes are locale-dependent, they match characters based on the system’s linguistic rules rather than strict ASCII values. In a UTF-8 environment, a class like [:alpha:] will match accented characters (e.g., é or ñ), whereas a literal range like [a-zA-Z] may not. A character class must be nested inside a bracket expression to function.
[[:digit:]]
[[:lower:][:upper:]]
[![:space:]]
Standard POSIX Classes:
  • [:alnum:]: Alphanumeric characters.
  • [:alpha:]: Alphabetic characters.
  • [:blank:]: Space and tab characters.
  • [:cntrl:]: Control characters.
  • [:digit:]: Decimal digits.
  • [:graph:]: Printable characters excluding space.
  • [:lower:]: Lowercase alphabetic characters.
  • [:print:]: Printable characters including space.
  • [:punct:]: Punctuation characters.
  • [:space:]: Whitespace characters (space, tab, newline, carriage return, form feed, vertical tab).
  • [:upper:]: Uppercase alphabetic characters.
  • [:xdigit:]: Hexadecimal digits.
Bash Extensions:
  • [:ascii:]: ASCII characters (range 0-127).
  • [:word:]: Alphanumeric characters plus underscore.

Equivalence Classes

An equivalence class is denoted by [=c=] and matches all characters that share the same base collation weight as the character c according to the current locale. This is used to group a base letter with its accented variants.
[[=e=]]
(Matches e, é, è, ê, etc., depending on the locale.)

Collating Symbols

A collating symbol is denoted by [.symbol.] and is used to match multi-character collating elements as a single entity within a bracket expression. This supports languages where two characters are treated as a single sorting unit (e.g., ch or ll in traditional Spanish collation).
[[.ch.]]

Special Character Placement Rules

To match characters that normally hold syntactic meaning within a bracket expression (], -, !, ^), they must be placed in specific positions to force literal interpretation:
  • Closing Bracket (]): Must be the first character in the set (or immediately following the negation operator).
[][]     # Matches ']' or '['
[!]]     # Matches any character except ']'
  • Hyphen (-): Must be the first or last character in the set to avoid being interpreted as a range operator.
[-abc]   # Matches '-', 'a', 'b', or 'c'
[abc-]   # Matches 'a', 'b', 'c', or '-'
  • Exclamation/Caret (!, ^): Must be placed anywhere except the first position to be treated as literal characters.
[a!b^]   # Matches 'a', '!', 'b', or '^'
Master Bash with Deep Grasping Methodology!Learn More