regular expression to convert state names to abbre

2019-08-24 03:15发布

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!

1条回答
成全新的幸福
2楼-- · 2019-08-24 04:17

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.

查看更多
登录 后发表回答