Skip to content

Instantly share code, notes, and snippets.

@matheus-santos
Last active May 21, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheus-santos/9809d43bd1791288737b4c0dc46703d6 to your computer and use it in GitHub Desktop.
Save matheus-santos/9809d43bd1791288737b4c0dc46703d6 to your computer and use it in GitHub Desktop.
Regex to add key name as value of property 'id' in object
Search: /^    ([a-zA-Z]+): {\n( +)/
Replace: /    $1: {\n$2id: '$1',\n$2/

Example:

{                             =>   {
 name: {                      =>     name: {
   property1: 'Property 1'    =>       id: 'name', // Added
 }                            =>       property1: 'Property 1',
}                             =>     }
                              =>   }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment