regular expression to convert state names to abbreviations

萝らか妹 提交于 2019-12-11 16:34:12

问题


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:


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.



来源:https://stackoverflow.com/questions/5598214/regular-expression-to-convert-state-names-to-abbreviations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!