Regex for semantic version
/\bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?\b/g
Matches
Examples
Note
Follows semver.org: no leading zeros, optional pre-release after a hyphen and build metadata after a plus.
Matches in the example
"1.2.3""v2.0.0-rc.1+build.5"
Token by token
\ba word boundaryv?the character “v”, optionally(?:a group, not capturing0the character “0”|or[1-9]one of: “1” to “9”\d*a digit (0–9), zero or more times, as many as possible)end of group\.the character “.”(?:a group, not capturing0the character “0”|or[1-9]one of: “1” to “9”\d*a digit (0–9), zero or more times, as many as possible)end of group\.the character “.”(?:a group, not capturing0the character “0”|or[1-9]one of: “1” to “9”\d*a digit (0–9), zero or more times, as many as possible)end of group(?:a group, not capturing-the character “-”[0-9A-Za-z.-]+one of: “0” to “9”, “A” to “Z”, “a” to “z”, “.” or “-”, one or more times, as many as possible)?end of group, whole group optionally(?:a group, not capturing\+the character “+”[0-9A-Za-z.-]+one of: “0” to “9”, “A” to “Z”, “a” to “z”, “.” or “-”, one or more times, as many as possible)?end of group, whole group optionally\ba word boundary
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