BASH commands: Wildcards I
Description:
In BASH there's a simple, yet a powerful feature, called the wildcards. In this first iteration of the problem, we will tackle the most basic of all wildcards in BASH, - the question mark ?
wildcard.
So when does this all get used? Whenever searching for a file, sometimes you might be interested in matching a set of files based on their name, for example given a list of files:
- aa.jpg
- ab.jpg
- ac.jpg
- za.jpg
- zb.jpg
We might be interested in selecting all the files starting with an a
character, such as: aa.jpg
, ab.jpg
and ac.jpg
. For this particular case, we would use: a?.jpg
, to get the desired result.
The question mark wildcard ?
is very similar in its behavior to the .
in Regexp, that is, it matches any character as long as its there. For example, .?
will match .a
and ._
, but not a
and not .
. This effectively implies that the pattern length should equal the length of the matched string.
The question mark wildcard ?
can be used in a pattern as many times as necessary. For example, ?b?.gif
or ???.elf
or even ????
.
Given a string pattern
representing the pattern that may or may not contain wildcards, and a string filename
, return a truthy value if the given pattern matches the filename, or a falsy value, if it doesn't.
If you have any questions and or suggestions regarding the task, please feel free to write in the discussions. Have fun!
Similar Kata:
Stats:
Created | May 30, 2017 |
Published | May 31, 2017 |
Warriors Trained | 104 |
Total Skips | 8 |
Total Code Submissions | 70 |
Total Times Completed | 39 |
C Completions | 39 |
Total Stars | 2 |
% of votes with a positive feedback rating | 89% of 27 |
Total "Very Satisfied" Votes | 21 |
Total "Somewhat Satisfied" Votes | 6 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 24 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |