Code & Markup · In-Browser Regular Expression Lab
JSON Key Regex — Extract All Object Keys from JSON Text
Captures all property keys from JSON formatted strings using lookahead for the colon separator.
Flags:
//g
Match Found
Load Sample:
Match Inspection & Details3 matches
Match #1:"id":
Match #2:"name":
Match #3:"active":
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
{"id": 10, "name": "Castov", "active": true} Pass
Expected Invalid Samples (Must Reject)
["value1", "value2"] Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:/g;
const text = "{\"id\": 10, \"name\": \"Castov\", \"active\": true}";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Matches double-quoted identifier strings followed immediately by a colon. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| " | Opening quote | Literal double quote. |
| ([a-zA-Z_][a-zA-Z0-9_]*) | Key Identifier | Captures standard property key. |
| "\s*: | Colon separator | Trailing quote and JSON key delimiter. |
Frequently Asked Questions
Does this match values in quotes?
Related Regular Expressions
Browse All 40 PatternsData & Formatting
CSV Comma-Separated Line Parser
Splits a CSV line into fields respecting quotes around fields with embedded commas.
/(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,"]*))/gTest regex
Code & Markup
.env Configuration Key-Value
Parses standard `.env` file entries matching uppercase snake_case keys and their string values.
/^([A-Z_][A-Z0-9_]*)=(.*)$/mTest regex
Code & Markup
HTML Tags Matcher & Stripper
Matches HTML markup tags for sanitization, stripping, or token extraction.
/<\/?[a-zA-Z][a-zA-Z0-9]*(?:\s+[^>]*?)?\/?>/gTest regex