WIPIVERSE All articles

Wildcard character

A wildcard character is a special symbol used in computing and information technology to represent one or more unspecified characters in a string, enabling flexible pattern matching. Wildcards are commonly employed in search operations, file name expansions, database queries, and programming languages to simplify the specification of multiple possible values without enumerating each explicitly.

Typical Wildcard Symbols

Symbol Meaning in most contexts Common usage
* Matches zero or more characters File‑system globbing (e.g., *.txt matches all files ending with .txt)
? Matches exactly one character Command‑line utilities (e.g., file?.doc matches file1.doc, fileA.doc)
[ … ] Matches any one character within a set or range Shell patterns (e.g., file[0-9].txt matches file0.txt … file9.txt)
{ … } Matches any of a list of alternatives (often called "brace expansion") Bash (e.g., file{a,b,c}.txt expands to filea.txt, fileb.txt, filec.txt)
% In SQL’s LIKE operator, matches zero or more characters SELECT * FROM Employees WHERE Name LIKE 'A%';
_ In SQL’s LIKE operator, matches exactly one character SELECT * FROM Products WHERE Code LIKE '12_5';

Contexts of Use

  1. Shell Globbing – Unix‑like command‑line shells (e.g., Bash, Zsh, PowerShell) use wildcards to expand file‑name patterns before executing a command. For example, rm *.log deletes all files whose names end with .log.

  2. Programming Languages – Many languages provide libraries for pattern matching that incorporate wildcard syntax. For instance:

    • In Python, the fnmatch and glob modules implement Unix‑style wildcards.
    • In Java, java.nio.file.PathMatcher can be created with a "glob:" syntax.
  3. Database Queries – Structured Query Language (SQL) employs % and _ as wildcards within the LIKE predicate to filter rows based on partial string matches.

  4. Search Engines and Text Editors – Some applications support wildcard characters in their find/replace dialogs, allowing users to locate text fragments without knowing the exact characters.

  5. Regular Expressions – Though not termed “wildcards” in formal regex syntax, the concepts overlap. The . metacharacter in regular expressions matches any single character, similar to ? in glob patterns, while .* matches any sequence of characters, analogous to *.

Behavioral Details

  • Wildcard interpretation is context‑dependent; the same symbol may have different meanings in different systems. For example, * in a shell expands to any string of characters, while in SQL % serves that role.
  • Matching is generally case‑sensitive on case‑sensitive file systems (e.g., typical Unix/Linux environments) and case‑insensitive on case‑insensitive systems (e.g., default Windows file systems) unless explicitly overridden.
  • Some implementations support escape characters (e.g., \*) to treat a wildcard symbol literally rather than as a pattern operator.

Historical Notes

The term “wildcard” originates from card games, where a “wild card” can stand for any other card. The metaphor was adopted in computing to describe characters that could stand for any other character(s) in textual patterns. Early implementations appear in command‑line utilities and operating‑system file management tools from the 1970s and 1980s, such as the CP/M and MS‑DOS DIR commands.

Browse

More topics to explore

    Browse all articles