Menu

#4 Glossery: Regular expression vs. Wildcards

open
nobody
None
5
2003-04-16
2003-04-16
Martin H
No

[I don't qualify as newbie, but anyway]
[I split this into multiple bug reports, so you can fix
discuss them one at a time]

Regular expressions:
> One of the most powerful features of any Unix system
is the >"regular expression" (also called "regexp" ).
It is a series of >special characters that are used to
design patterns
This part is right, but the rest of your explaination
describes wildcards or shell globs.
regular expressions are used for pattern matching
(usually not generating a list of strings but they can
be used in that way to)

In short regular expressions are what is used by egrep
and perl, see man perlre for further descriptions.

>>rm *.hop
>will remove all files that end by .hop ,whereas
the regular expression that matches exerything ending
in .hop is
\.hop$
the backslash escapes the special character '.' and
matches it literally
>>rm [Hh]op
>will remove files hop and/or Hop.
Ok this is a regular expression but depending on
option, it usually matches anything containing Hop or
hop. Use
^[Hh]op$
to match only Hop and hop
the Shell's globing syntax looks really similar but is
a bit different in this case.

Wildcards:
I'd say that wildcards are not regular expressions.
But i don't know a good definion. I think wildcards are
things that match stuff according to a pattern that
pattern being in any pattern "language" known to
exists. In the shell environment usually shell globing
is used as pattern language.

You might consider adding a section about shell globing
or shell pattern matching if you prefer that:
see
$ info bash "concept index" "Pattern Matching"
and
$ info bash "Basic Shell Features" "shell expansions"
"Filename Expansion"

Discussion


Log in to post a comment.