
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to write Python regular expression to match with file extension?
The following code using regex matches the file extension in the given file name.
Example
import re result = re.search('.doc$', '87654_3.doc') print result.group()
Output
This gives the output
.doc
- Related Articles
- How to write a Python regular expression to match multiple words anywhere?
- How to match parentheses in Python regular expression?
- How to write a regular expression to match either a or b in Python?
- How to match a word in python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- How to put variable in regular expression match with JavaScript?
- How to match a nonwhitespace character in python using Regular Expression?
- How to match a single character in python using Regular Expression?
- How to write a Python regular expression to use re.findall()?
- How to write a Python Regular Expression to validate numbers?
- How to write Python regular expression to check alphanumeric characters?
- How to match any one lowercase vowel in python using Regular Expression?
- How do we use Python regular expression to match a date string?
- Explain Python regular expression search vs match

Advertisements