0

I'm working on a project that requires only the use of regular expression to convert state names (must be case insensitive) to their two letter abbreviations.

I cannot use any sort of development environment or link to any databases or xml or ini files.

Please help!

Larry
  • 1
  • 1
  • There are only 51 states, 51 abreviations, all arbitrary. Its usually the first 2 letters on a single word state, double word state, its the first letter of each word. But there are exceptions. –  Apr 08 '11 at 16:45
  • 1
    That is a bizarre and nonsensical requirement - can you explain more about why you need to solve the problem in this way? – Carl Norum Apr 08 '11 at 16:45

1 Answers1

2

Since states don't have something regular in them regular expressions is the WRONG tool. I would suggest getting a new project.

However, the only solution (apart from stupid illogical hacks) is to hardcore every state:

s/Alabama/Al/
s/Alaska/Ak/
...
s/Wyoming/Wy/

A list of the states and their abbreviations can be found here.

orlp
  • 112,504
  • 36
  • 218
  • 315