Wildcards or joker characters such as * or ? denote a placeholder for other characters and you are probably familiar with these from working in a console.
In the following table, wildcards and their extensions are described and the placeholder properties are mentioned:
Wildcard | Description: Matches exactly … or is placeholder for exactly … |
---|---|
* | One or more characters |
? | One character |
[mMbB] | One character from the character set |
[a-d] | One character from the given range |
[!mMbB] | Any character that is not in the character set |
[!a-d] | Any character that is not in the specified range |
{txt,log,csv} | One of the three 'words' in the comma-separated list |
Table 19.6.1.1: Often used wildcards in a console
Searches for all files in the current directory
hans@linux:~$ ls -l [pP]*.??? -rwxrwxrwx 1 hans hans 467 Dez 26 20:30 parametertest.sh~ -rw------- 1 hans hans 0 Okt 27 19:54 perl.cgi -rw------- 1 hans hans 225 Mai 11 2011 pgausgabe.sql
hans@linux:~$ ls -l [m]*.*[~] -rwx--x--x 1 hans hans 270 Dez 29 14:41 myName.script~ -rw------- 1 hans hans 3022 Dez 29 16:00 mysql.gbs~
hans@linux:~$ ls -l [kKmM]*.gb{s,w} -rw------- 1 hans hans 1616 Mai 14 2012 kontakt.gbw -rwx--x--x 1 hans hans 2018 Jan 3 2012 m.gbs -rw------- 1 hans hans 1984 Jan 3 2012 m.gbw -rwx--x--x 1 hans hans 3022 Dez 29 16:00 mysql.gbs
The console editor sed, through the use of regular expressions - in conjunction with the SHELL and EXEC instructions - offers extensive possibilities for conveniently working with text files and and their contents (strings). The following example is intended to demonstrate the power of the sed programme:
hans@linux:~$ sed 's/\bProgramm\b/Projekt/g' --in-place=.bak $HOME/a_sed.txt
What does this cryptic-looking line do? In the file a_sed.txt, the (isolated) word programme globally (/g) - i.e. in the entire text content - is to be replaced by the word project and the original file with the extension .bak is to be saved in the file with the file name originalfilename.bak.
If such a one-liner can inspire you, then this is the right motivation to deal (more intensively) with regular expressions and their use in Gambas projects.