Regex for Document File Extension
Regex Pattern
\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|rtf|odt)$Common document file extensions
Quick Answer
The regex pattern for document file extension is `\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|rtf|odt)$`. Common document file extensions. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| report.pdf | ✓ Matches |
| data.xlsx | ✓ Matches |
| slides.pptx | ✓ Matches |
| notes.txt | ✓ Matches |
| image.jpg | ✗ No match |
| script.js | ✗ No match |
| document | ✗ No match |
Code Examples
javascript
const regex = /\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|rtf|odt)$/; const isValid = regex.test(value);
python
import re
pattern = r'\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|rtf|odt)$'
if re.match(pattern, value):
print("valid")ruby
pattern = /\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|rtf|odt)$/ if value =~ pattern puts "valid" end
php
if (preg_match('/\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|rtf|odt)$/', $value)) {
echo "valid";
}java
String pattern = "\\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|rtf|odt)$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
File Extension
File extension at the end of a filename
Image File Extension
Common image file extensions
Video File Extension
Common video file extensions
Absolute Unix Path
Absolute filesystem path starting with /
Windows File Path
Windows absolute file path (C:\folder\file.txt)
Unix File Path
Unix absolute file path (must have at least one path component)