Regular Expressions with GLOB Module
Regular Expressions with GLOB Module: -
- The glob module in Python is used for pattern matching with file names and directories.
- It works like wildcards in command-line shells.
- It is not full regular expression, but it uses special symbols like *, ?, and [ ] for matching.
- The glob module is a built-in module in python. If in case it is missing, we can install using
Py -m pip install glob2.
- To use glob( ) and its related functions, we need t import glob module. This function returns a list of all files matching a given pattern.
1) Search exact string with glob( ): -
- To search for a file with an exact name, just pass the filename.
output: -
3) single character search with glob( ): -
- single character ( ? ) matches exactly one character.
4) multiple character search with glob( ): -
- [ ] matches any
one character inside the brackets.