Wildcards

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Wildcards:

Wildcards are symbols used to represent one or more characters in a file or


directory name.
Common wildcards in Linux include:
* (asterisk): Matches zero or more characters.
? (question mark): Matches any single character.
[ ] (brackets): Matches any one character within the specified range or set.
Wildcards are typically used in commands like ls, cp, mv, etc., to perform
operations on multiple files that match a certain pattern.
Regular Expressions (Regex):

Regular expressions are patterns used to match character combinations in strings.


They provide more sophisticated matching capabilities than wildcards.
Regex patterns can include various special characters and metacharacters to define
complex search patterns.
Regular expressions are widely used in text processing utilities like grep, sed,
awk, etc., for tasks such as searching, replacing, and filtering text based on
patterns.
Regex patterns can match specific sequences of characters, ranges of characters,
repetitions, groupings, etc.
Literals: Literal characters in a regular expression match themselves. For example,
the regex hello will match the string "hello" in the text.

Metacharacters: Special characters with predefined meanings in regex. Some common


metacharacters include:

. (dot): Matches any single character except newline.


*: Matches zero or more occurrences of the preceding character or group.
+: Matches one or more occurrences of the preceding character or group.
?: Matches zero or one occurrence of the preceding character or group.
^: Anchors the regex to the beginning of the line.
$: Anchors the regex to the end of the line.
[]: Defines a character class, matching any single character within the brackets.
|: Alternation, matches either the expression before or after the pipe symbol.
Character Classes: Square brackets [ ] are used to specify a set of characters to
match. For example, [aeiou] matches any vowel.

Quantifiers: Define how many occurrences of a character or group should be matched.


Quantifiers include *, +, ?, and {}.

Grouping and Capturing: Parentheses () are used to group parts of a regex together.
They also create capture groups, allowing you to extract matched substrings.

Anchors: ^ and $ are used to anchor a regex to the beginning and end of a line,
respectively.

Escaping: Backslash \ is used to escape metacharacters if you want to match them


literally. For example, \. matches a literal dot character.

Modifiers: Modifiers change the behavior of a regex. Common modifiers include i for
case-insensitive matching and g for global matching.
Summary:

Wildcards are simpler and more limited in functionality, primarily used for basic
pattern matching in file and directory names.
Regular expressions are more powerful and flexible, allowing complex pattern
matching and manipulation of text data.
While wildcards are commonly used in shell commands for file operations, regular
expressions are used in text processing utilities for more advanced text
manipulation tasks

You might also like