| Start | ||||||||
|---|---|---|---|---|---|---|---|---|
| Check if a string matches a regular expression Check if a string consists in exactly 8 digits: |
||||||||
| Behaviour when a glob does not match anything Preparation In case the glob does not match anything the result is determined by the
options If If Notice, that the |
||||||||
Get captured groups from a regex match against a string Output: |
||||||||
| The * glob Preparation The asterisk * is probably the most commonly used glob. It simply matches any String A single * will not match files and folders that reside in subfolders |
||||||||
| The ** glob Preparation Bash is able to interpret two adjacent asterisks as a single glob. With the The |
||||||||
| The ? glob Preparation The |
||||||||
| The [ ] glob Preparation If there is a need to match specific characters then '[]' can be used. Any character inside '[]' will be matched exactly once. The Here we are telling bash the we want to match only files which do not not
start with a Ranges can be matched by seperating a pair of characters with a hyphen ( Character classes can be matched by |
||||||||
| Matching hidden files Preparation The Bash built-in option dotglob allows to match hidden files
and folders, i.e., files and folders that start with a |
||||||||
| Case insensitive matching Preparation Setting the option |
||||||||
| Extended globbing Preparation Bash's built-in The following sub-patterns comprise valid extended globs:
The The It matches anything that does not start with zero or more occurrences of the
letters |
||||||||
Regex matching Output: Instead of assigning the regex to a variable ( Explanation
Syntax
RemarksCharacter Classes Valid character classes for the alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit Inside will match any file that starts with an It should be kept in mind, though, that a The following does match all files that start with either a digit or a It does not match any file or folder that starts with with letter except an Escaping glob characters It is possible that a file or folder contains a glob character as part of its name. In this case a glob can be escaped with a preceding Difference to Regular Expressions The most significant difference between globs and Regular Expressions is that
a valid Regular Expressions requires a qualifier as well as a quantifier.
A qualifier identifies what to match and a quantifier tells how often
to match the qualifier. The equivalent RegEx to the Equivalent Regular Expressions
|
Read Article
https://develop.horje.com/learn/1434/reference