Regular Expressions 101

Community Patterns

Swap key and value in JavaScript object

1

Regular Expression
PCRE (PHP <7.3)

/
([a-zA-Z0-9\_]*)\:\s?([A-Za-z0-9\"\']*)
/
mg

Description

This will allow you to swap key and value in a JavaScript object. So { language: "romanian" } will become { romanian: "language" }

Submitted by Victor - 8 years ago