Regex for file extension
/\.([a-z0-9]{1,10})$/gim
Matches
Examples
Note
Group 1 is the extension. For archive.tar.gz it is gz, the last one.
Matches in the example
".pdf"".gz"".JPEG"
Token by token
\.the character “.”(a capturing group[a-z0-9]{1,10}one of: “a” to “z” or “0” to “9”, between 1 and 10 times, as many as possible)end of group$the end of the string (or line, with the m flag)
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma