Skip to content

Instantly share code, notes, and snippets.

@mfurlend
Created June 6, 2014 14:32
Show Gist options
  • Save mfurlend/4112aa0c8c2027230f0d to your computer and use it in GitHub Desktop.
Save mfurlend/4112aa0c8c2027230f0d to your computer and use it in GitHub Desktop.
regex for javascript to switch key:value => value:key for objects
search: ([ ]*)(.*?):\s?([^,\n\r]*)
repalce: $1$3:$2
example:
var regionNames = {
"australia":"Australia",
"brazil":"Brazil",
"canada":"Canada",
"caribbean":"Caribbean",
"centamer":"Central America",
"centasia":"Central Asia",
"chile":"Chile",
"china":"China",
"eastafr":"East Africa",
"europe":"Europe",
"greenland":"Greenland & Iceland",
"korea":"Japan & Korea",
"mexico":"Mexico",
"mideast":"Middle East",
"northafr":"North Africa",
"northsamer":"N. South America",
"peruecuador":"Peru & Ecuador",
"russia":"Russia",
"seasia":"SE Asia",
"southafr":"S. South Africa",
"southasia":"South Asia",
"southsamer":"S. South America",
"ukraine":"Ukraine",
"usa":"United States",
"westafr":"West Africa"
};
becomes
var regionNames = {
"Australia":"australia",
"Brazil":"brazil",
"Canada":"canada",
"Caribbean":"caribbean",
"Central America":"centamer",
"Central Asia":"centasia",
"Chile":"chile",
"China":"china",
"East Africa":"eastafr",
"Europe":"europe",
"Greenland & Iceland":"greenland",
"Japan & Korea":"korea",
"Mexico":"mexico",
"Middle East":"mideast",
"North Africa":"northafr",
"N. South America":"northsamer",
"Peru & Ecuador":"peruecuador",
"Russia":"russia",
"SE Asia":"seasia",
"S. South Africa":"southafr",
"South Asia":"southasia",
"S. South America":"southsamer",
"Ukraine":"ukraine",
"United States":"usa",
"West Africa":"westafr"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment