A Table of Practical Matching Differences Between Pattern Matching Notation Used in Pathname and Parameter Expansion and Extended Regular Expressions

This post is part of a series on the difference between pattern matching notation and extended regular expressions.

After exploring the differences between pattern matching notation used in pathname and parameter expansion and regular expressions theoretically as well as practically, this table serves as an overview of the basic practical differences when it comes to fulfilling matching tasks. If you have any more tasks to add please request them in the comments section.

Matching Task Extended Regular Expressions Pattern Matching Notation
Pathname Expansion Parameter Expansion
${parameter#pattern} ${parameter##pattern} ${parameter%pattern} ${parameter%pattern} ${parameter/pattern/string}
Character c only c c only matches if a pathname is just c, otherwise it won’t match except full filenames/pathnames Can only match a c in the beginning or end, not in the middle c
Character c 0 or more times c+ No operator
Character c 1 or more times c*
Character c 0 or 1 time c?
Character c 0-3 times c{0,3} No Bounds in Pattern Matching Notation
Any String .* * * will only match the null string because it is the shortest * * will only match the null string because it is the shortest * *
String beginning with character c ^c.* c* c* will only match the c because it is the shortest c* c* might match a shorter substring No way to specify beginning and end anchors
String ending with c .*c$ *c *c may match a shorter substring ending with c *c
String containing character c .*c.* *c* *c* will only match up to the c *c* *c* will only match from the last c till the end *c* *c*

Ahmed Amayem has written 90 articles

A Web Application Developer Entrepreneur.