^ matches the beginning of every line. Given the string function() { } using /^\{/ will match the final } because it's at the beginning of the line