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.

            Example: -

            output: -


2) glob module with asterisk ( * ) wildcard: -

  • matches zero or more characters in file names.


            Example: -

            output: -


3) single character search with glob( ): -

  • single character ( ? ) matches exactly one character.


            Example: -


            output: -


4) multiple character search with glob( ): -  

  • [ ] matches any one character inside the brackets.


            Example: -

            output: -



Popular posts from this blog

operators in c programming

Variables in c

Cloud Storage and Local Storage: Applications in Business