I’m trying to find aiport codes given a string like (JFK) or [FRA] using a regular expression.
I’m don’t have to make sure if the mentioned airport code is correct. The braces can pretty much contain any three capital letters.
Here’s my current solution which does work for round brackets but not for square brackets:
[((\[]([A-Z]{{3}})[))\]]
Thanks!
Your regular expression seems like it is try to match too much, try this one:
^matches the beginning of the line (something you may or may not need)[(\[]is a character class that matches(or[[A-Z]{3}matches three capitol letters[)\]]is a character class that matches)or]$matches the end of the line (something you may or may not need)Click here to see the test results
Note that
[and]are special characters in regular expressions and I had to escape them with a\to indicate I wanted a literal character.Hope this helps