Regex for trailing comma
/,(?=\s*[\]}])/g
Matches
Examples
Note
The lookahead finds commas followed by a closing bracket without consuming it. Replace with nothing to clean up near-JSON.
Matches in the example
","","
Token by token
,the character “,”(?=followed by (lookahead, not consumed)\s*a whitespace character, zero or more times, as many as possible[\]}]one of: the character “]” or “}”)end of group
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