← Back to challenges

Grab the City

JavaScriptHardregexstrings

Instructions

Write a function to return the city from each of these vacation spots.

Examples

grabCity("[Last Day!] Beer Festival [Munich]") ➞ "Munich"

grabCity("Cheese Factory Tour [Portland]") ➞ "Portland"

grabCity("[50% Off!][Group Tours Included] 5-Day Trip to Onsen [Kyoto]") ➞ "Kyoto"

Notes

There may be additional brackets, but the city will always be in the last bracket pair.

javascript
Loading editor…
⌘ ↵ to run
Walks through the solution with reasoning and edge cases.